@yukiakai/events-async 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Yuki Akai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # @yukiakai/events-async
2
+
3
+ [![NPM Version][npm-version-image]][npm-url]
4
+ [![NPM Downloads][npm-downloads-image]][npm-downloads-url]
5
+
6
+ [![Build Status][github-build-url]][github-url]
7
+ [![codecov][codecov-image]][codecov-url]
8
+
9
+ Drop-in replacement for Node.js `EventEmitter` with **async listener support**.
10
+ Supports **`emitAsync`** (parallel) and **`emitSeries`** (sequential) execution of listeners, and is fully type-safe in TypeScript.
11
+ Works with both **string** and **symbol** event names.
12
+
13
+ ---
14
+
15
+ ## Features
16
+
17
+ - Fully TypeScript type-safe (`on`, `off`)
18
+ - Async listeners supported
19
+ - `emitAsync`: run all listeners in parallel
20
+ - `emitSeries`: run listeners sequentially
21
+ - Supports **string** and **symbol** keys for events
22
+ - Compatible with Node.js `EventEmitter` API
23
+
24
+ ---
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install @yukiakai/events-async
30
+ # or
31
+ yarn add @yukiakai/events-async
32
+ ````
33
+
34
+ ---
35
+
36
+ ## Usage
37
+
38
+ ```ts
39
+ import { EventEmitterAsync } from '@yukiakai/events-async';
40
+
41
+ const SYMBOL_EVENT = Symbol('symbolEvent');
42
+
43
+ interface MyEvents {
44
+ hello: (name: string) => void | Promise<void>;
45
+ count: (n: number) => void | Promise<void>;
46
+ [SYMBOL_EVENT]: (msg: string) => void | Promise<void>;
47
+ }
48
+
49
+ const ee = new EventEmitterAsync<MyEvents>();
50
+
51
+ // Type-safe listener
52
+ ee.on('hello', async (name) => {
53
+ console.log('Hello', name);
54
+ });
55
+
56
+ ee.on(SYMBOL_EVENT, (msg) => {
57
+ console.log('Symbol event:', msg);
58
+ });
59
+
60
+ // Emit asynchronously (parallel)
61
+ await ee.emitAsync('hello', 'world');
62
+ await ee.emitAsync(SYMBOL_EVENT, 'ok');
63
+
64
+ // Emit sequentially (in order)
65
+ await ee.emitSeries('hello', 'world');
66
+ ```
67
+
68
+ ---
69
+
70
+ ## API
71
+
72
+ See docs: [API Docs][api-docs-url]
73
+
74
+ ### `on(event, listener)`
75
+
76
+ Register a listener with type safety.
77
+ `event` can be `string` or `symbol`.
78
+
79
+ ### `off(event, listener)`
80
+
81
+ Remove a listener (type-safe).
82
+
83
+ ### `emitAsync(event, ...args)`
84
+
85
+ Run all listeners in parallel, await completion.
86
+
87
+ ### `emitSeries(event, ...args)`
88
+
89
+ Run listeners **in order**, await completion.
90
+
91
+ ---
92
+
93
+ ### Notes
94
+
95
+ * Supports both **sync** and **async** listeners.
96
+ * `string | symbol` keys fully supported.
97
+
98
+ ---
99
+
100
+ ## Development
101
+
102
+ ```bash
103
+ npm install
104
+ npm run build
105
+ npm run test
106
+ npm run lint
107
+ ```
108
+
109
+ ---
110
+
111
+ ## Changelog
112
+
113
+ See full release notes in [CHANGELOG.md][changelog-url]
114
+
115
+ ---
116
+
117
+ ## License
118
+
119
+ MIT © [Yuki Akai](https://github.com/yukiakai212)
120
+
121
+ ---
122
+
123
+ [npm-downloads-image]: https://badgen.net/npm/dm/@yukiakai/events-async
124
+ [npm-downloads-url]: https://www.npmjs.com/package/@yukiakai/events-async
125
+ [npm-url]: https://www.npmjs.com/package/@yukiakai/events-async
126
+ [npm-version-image]: https://badgen.net/npm/v/@yukiakai/events-async
127
+ [github-build-url]: https://github.com/yukiakai212/events-async/actions/workflows/build.yml/badge.svg
128
+ [github-url]: https://github.com/yukiakai212/events-async/
129
+ [codecov-image]: https://codecov.io/gh/yukiakai212/events-async/branch/main/graph/badge.svg
130
+ [codecov-url]: https://codecov.io/gh/yukiakai212/events-async
131
+ [changelog-url]: https://github.com/yukiakai212/events-async/blob/main/CHANGELOG.md
132
+ [api-docs-url]: https://yukiakai212.github.io/events-async/
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var o=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var d=(t,s)=>{for(var e in s)o(t,e,{get:s[e],enumerable:!0})},l=(t,s,e,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of K(s))!y.call(t,r)&&r!==e&&o(t,r,{get:()=>s[r],enumerable:!(n=m(s,r))||n.enumerable});return t};var E=t=>l(o({},"__esModule",{value:!0}),t);var f={};d(f,{EventEmitterAsync:()=>i});module.exports=E(f);var a=require("events"),i=class extends a.EventEmitter{async emitAsync(s,...e){let n=this.listeners(s);await Promise.all(n.map(r=>r(...e)))}async emitSeries(s,...e){let n=this.listeners(s);for(let r of n)await r(...e)}on(s,e){return super.on(s,e)}addListener(s,e){return super.addListener(s,e)}off(s,e){return super.off(s,e)}removeListener(s,e){return super.removeListener(s,e)}};0&&(module.exports={EventEmitterAsync});
@@ -0,0 +1,12 @@
1
+ import { EventEmitter } from 'node:events';
2
+
3
+ declare class EventEmitterAsync<E extends Record<string | symbol, (...args: unknown[]) => unknown> = Record<string | symbol, (...args: any[]) => any>> extends EventEmitter {
4
+ emitAsync<K extends keyof E>(event: K, ...args: Parameters<E[K]>): Promise<void>;
5
+ emitSeries<K extends keyof E>(event: K, ...args: Parameters<E[K]>): Promise<void>;
6
+ on<K extends keyof E>(event: K, listener: E[K]): this;
7
+ addListener<K extends keyof E>(event: K, listener: E[K]): this;
8
+ off<K extends keyof E>(event: K, listener: E[K]): this;
9
+ removeListener<K extends keyof E>(event: K, listener: E[K]): this;
10
+ }
11
+
12
+ export { EventEmitterAsync };
@@ -0,0 +1,12 @@
1
+ import { EventEmitter } from 'node:events';
2
+
3
+ declare class EventEmitterAsync<E extends Record<string | symbol, (...args: unknown[]) => unknown> = Record<string | symbol, (...args: any[]) => any>> extends EventEmitter {
4
+ emitAsync<K extends keyof E>(event: K, ...args: Parameters<E[K]>): Promise<void>;
5
+ emitSeries<K extends keyof E>(event: K, ...args: Parameters<E[K]>): Promise<void>;
6
+ on<K extends keyof E>(event: K, listener: E[K]): this;
7
+ addListener<K extends keyof E>(event: K, listener: E[K]): this;
8
+ off<K extends keyof E>(event: K, listener: E[K]): this;
9
+ removeListener<K extends keyof E>(event: K, listener: E[K]): this;
10
+ }
11
+
12
+ export { EventEmitterAsync };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{EventEmitter as o}from"events";var n=class extends o{async emitAsync(s,...e){let r=this.listeners(s);await Promise.all(r.map(t=>t(...e)))}async emitSeries(s,...e){let r=this.listeners(s);for(let t of r)await t(...e)}on(s,e){return super.on(s,e)}addListener(s,e){return super.addListener(s,e)}off(s,e){return super.off(s,e)}removeListener(s,e){return super.removeListener(s,e)}};export{n as EventEmitterAsync};
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@yukiakai/events-async",
3
+ "version": "1.0.0",
4
+ "description": "Drop-in replacement for Node.js EventEmitter with async listener support (emitAsync).",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.cjs"
12
+ },
13
+ "scripts": {
14
+ "test": "npm run build && npx vitest run --reporter verbose --coverage",
15
+ "format": "prettier --write **/*.{js,ts}",
16
+ "format:check": "prettier --check **/*.{js,ts}",
17
+ "lint": "eslint src/**/*.ts",
18
+ "build": "npx tsup",
19
+ "docs": "npx typedoc"
20
+ },
21
+ "files": [
22
+ "dist/*",
23
+ "CHANGELOG.md"
24
+ ],
25
+ "keywords": [
26
+ "eventemitter",
27
+ "async",
28
+ "typescript",
29
+ "events",
30
+ "emit-async",
31
+ "emit-series",
32
+ "await"
33
+ ],
34
+ "author": "Yuki_akai",
35
+ "homepage": "https://github.com/yukiakai212/events-async",
36
+ "engines": {
37
+ "node": ">= 16"
38
+ },
39
+ "maintainers": [
40
+ {
41
+ "name": "Yuki_akai",
42
+ "homepage": "https://github.com/yukiakai212"
43
+ }
44
+ ],
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/yukiakai212/events-async.git"
48
+ },
49
+ "bugs": {
50
+ "url": "https://github.com/yukiakai212/events-async/issues"
51
+ },
52
+ "license": "MIT",
53
+ "devDependencies": {
54
+ "@changesets/cli": "^2.29.5",
55
+ "@eslint/js": "^9.30.1",
56
+ "@types/node": "^24.0.10",
57
+ "@vitest/coverage-v8": "^3.2.4",
58
+ "eslint": "^9.30.0",
59
+ "prettier": "^3.6.2",
60
+ "tsup": "^8.5.0",
61
+ "tsx": "^4.20.3",
62
+ "typedoc": "^0.28.9",
63
+ "typescript": "^5.8.3",
64
+ "typescript-eslint": "^8.35.1",
65
+ "vitest": "^3.2.4"
66
+ }
67
+ }