{"_id":"@tootallnate/once","_rev":"994126","name":"@tootallnate/once","description":"Creates a Promise that waits for a single event","dist-tags":{"latest":"3.0.0"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"time":{"modified":"2021-09-27T09:15:56.000Z","created":"2020-02-08T23:48:05.016Z","3.0.0":"2021-09-27T09:13:54.973Z","2.0.0":"2021-09-22T23:50:52.041Z","1.1.2":"2020-04-21T15:40:59.696Z","1.1.1":"2020-04-20T23:30:59.787Z","1.1.0":"2020-04-20T22:27:59.335Z","1.0.0":"2020-02-08T23:48:05.016Z"},"users":{},"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://n8.io/"},"repository":{"type":"git","url":"git://github.com/TooTallNate/once.git"},"versions":{"3.0.0":{"name":"@tootallnate/once","version":"3.0.0","description":"Creates a Promise that waits for a single event","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"prebuild":"rimraf dist","build":"tsc","test":"jest","prepublishOnly":"npm run build"},"repository":{"type":"git","url":"git://github.com/TooTallNate/once.git"},"keywords":[],"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://n8.io/"},"license":"MIT","bugs":{"url":"https://github.com/TooTallNate/once/issues"},"devDependencies":{"@types/jest":"^27.0.2","@types/node":"^12.12.11","abort-controller":"^3.0.0","jest":"^27.2.1","rimraf":"^3.0.0","ts-jest":"^27.0.5","typescript":"^4.4.3"},"engines":{"node":">= 10"},"jest":{"preset":"ts-jest","globals":{"ts-jest":{"diagnostics":false,"isolatedModules":true}},"verbose":false,"testEnvironment":"node","testMatch":["<rootDir>/test/**/*.test.ts"]},"gitHead":"2bc2e134b7728a6b37c6838a3b5d5c290e60a539","homepage":"https://github.com/TooTallNate/once#readme","_id":"@tootallnate/once@3.0.0","_nodeVersion":"12.22.6","_npmVersion":"6.14.15","dist":{"shasum":"d52238c9052d746c9689523e650160e70786bc9a","size":4447,"noattachment":false,"key":"/@tootallnate/once/-/@tootallnate/once-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@tootallnate/once/download/@tootallnate/once-3.0.0.tgz"},"_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"directories":{},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/once_3.0.0_1632734034811_0.33679291306743675"},"_hasShrinkwrap":false,"publish_time":1632734034973,"_cnpm_publish_time":1632734034973},"2.0.0":{"name":"@tootallnate/once","version":"2.0.0","description":"Creates a Promise that waits for a single event","main":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"prebuild":"rimraf dist","build":"tsc","test":"jest","prepublishOnly":"npm run build"},"repository":{"type":"git","url":"git://github.com/TooTallNate/once.git"},"keywords":[],"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://n8.io/"},"license":"MIT","bugs":{"url":"https://github.com/TooTallNate/once/issues"},"devDependencies":{"@types/jest":"^27.0.2","@types/node":"^12.12.11","abort-controller":"^3.0.0","jest":"^27.2.1","rimraf":"^3.0.0","ts-jest":"^27.0.5","typescript":"^4.4.3"},"engines":{"node":">= 10"},"jest":{"preset":"ts-jest","globals":{"ts-jest":{"diagnostics":false,"isolatedModules":true}},"verbose":false,"testEnvironment":"node","testMatch":["<rootDir>/test/**/*.test.ts"]},"gitHead":"b71b6e880044ab2110d3f2c753cd3d218e5e262e","homepage":"https://github.com/TooTallNate/once#readme","_id":"@tootallnate/once@2.0.0","_nodeVersion":"12.22.6","_npmVersion":"6.14.15","dist":{"shasum":"f544a148d3ab35801c1f633a7441fd87c2e484bf","size":3944,"noattachment":false,"key":"/@tootallnate/once/-/@tootallnate/once-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@tootallnate/once/download/@tootallnate/once-2.0.0.tgz"},"_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"directories":{},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/once_2.0.0_1632354651709_0.44949087906019014"},"_hasShrinkwrap":false,"publish_time":1632354652041,"_cnpm_publish_time":1632354652041},"1.1.2":{"name":"@tootallnate/once","version":"1.1.2","description":"Creates a Promise that waits for a single event","main":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"prebuild":"rimraf dist","build":"tsc","test":"mocha --reporter spec","test-lint":"eslint src --ext .js,.ts","prepublishOnly":"npm run build"},"repository":{"type":"git","url":"git://github.com/TooTallNate/once.git"},"keywords":[],"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://n8.io/"},"license":"MIT","bugs":{"url":"https://github.com/TooTallNate/once/issues"},"devDependencies":{"@types/node":"^12.12.11","@typescript-eslint/eslint-plugin":"1.6.0","@typescript-eslint/parser":"1.1.0","eslint":"5.16.0","eslint-config-airbnb":"17.1.0","eslint-config-prettier":"4.1.0","eslint-import-resolver-typescript":"1.1.1","eslint-plugin-import":"2.16.0","eslint-plugin-jsx-a11y":"6.2.1","eslint-plugin-react":"7.12.4","mocha":"^6.2.2","rimraf":"^3.0.0","typescript":"^3.7.3"},"engines":{"node":">= 6"},"gitHead":"3948afcb5803013e184861943e0018e37830fcfe","homepage":"https://github.com/TooTallNate/once#readme","_id":"@tootallnate/once@1.1.2","_nodeVersion":"10.20.1","_npmVersion":"6.14.4","dist":{"shasum":"ccb91445360179a04e7fe6aff78c00ffc1eeaf82","size":1693,"noattachment":false,"key":"/@tootallnate/once/-/@tootallnate/once-1.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/@tootallnate/once/download/@tootallnate/once-1.1.2.tgz"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/once_1.1.2_1587483659547_0.20019688772998245"},"_hasShrinkwrap":false,"publish_time":1587483659696,"_cnpm_publish_time":1587483659696},"1.1.1":{"name":"@tootallnate/once","version":"1.1.1","description":"Creates a Promise that waits for a single event","main":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"prebuild":"rimraf dist","build":"tsc","test":"mocha --reporter spec","test-lint":"eslint src --ext .js,.ts","prepublishOnly":"npm run build"},"repository":{"type":"git","url":"git://github.com/TooTallNate/once.git"},"keywords":[],"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://n8.io/"},"license":"MIT","bugs":{"url":"https://github.com/TooTallNate/once/issues"},"devDependencies":{"@types/node":"^12.12.11","@typescript-eslint/eslint-plugin":"1.6.0","@typescript-eslint/parser":"1.1.0","eslint":"5.16.0","eslint-config-airbnb":"17.1.0","eslint-config-prettier":"4.1.0","eslint-import-resolver-typescript":"1.1.1","eslint-plugin-import":"2.16.0","eslint-plugin-jsx-a11y":"6.2.1","eslint-plugin-react":"7.12.4","mocha":"^6.2.2","rimraf":"^3.0.0","typescript":"^3.7.3"},"engines":{"node":">= 6"},"gitHead":"7cf120c15c61306b143eee6ba388e18c2af1f434","homepage":"https://github.com/TooTallNate/once#readme","_id":"@tootallnate/once@1.1.1","_nodeVersion":"12.16.1","_npmVersion":"6.13.4","dist":{"shasum":"e94fe74465c49c36094f403b56df7ae99861f466","size":1579,"noattachment":false,"key":"/@tootallnate/once/-/@tootallnate/once-1.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/@tootallnate/once/download/@tootallnate/once-1.1.1.tgz"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/once_1.1.1_1587425459623_0.22249323277893485"},"_hasShrinkwrap":false,"publish_time":1587425459787,"_cnpm_publish_time":1587425459787},"1.1.0":{"name":"@tootallnate/once","version":"1.1.0","description":"Creates a Promise that waits for a single event","main":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"prebuild":"rimraf dist","build":"tsc","test":"mocha --reporter spec","test-lint":"eslint src --ext .js,.ts","prepublishOnly":"npm run build"},"repository":{"type":"git","url":"git://github.com/TooTallNate/once.git"},"keywords":[],"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://n8.io/"},"license":"MIT","bugs":{"url":"https://github.com/TooTallNate/once/issues"},"devDependencies":{"@types/node":"^12.12.11","@typescript-eslint/eslint-plugin":"1.6.0","@typescript-eslint/parser":"1.1.0","eslint":"5.16.0","eslint-config-airbnb":"17.1.0","eslint-config-prettier":"4.1.0","eslint-import-resolver-typescript":"1.1.1","eslint-plugin-import":"2.16.0","eslint-plugin-jsx-a11y":"6.2.1","eslint-plugin-react":"7.12.4","mocha":"^6.2.2","rimraf":"^3.0.0","typescript":"^3.7.3"},"engines":{"node":">= 6"},"gitHead":"ef4cb2ccd398f76498546588ca255220e74ac226","homepage":"https://github.com/TooTallNate/once#readme","_id":"@tootallnate/once@1.1.0","_nodeVersion":"12.16.1","_npmVersion":"6.13.4","dist":{"shasum":"6c8342b7d64b1ce1f9a8392c1f21b0da41e1f582","size":1644,"noattachment":false,"key":"/@tootallnate/once/-/@tootallnate/once-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@tootallnate/once/download/@tootallnate/once-1.1.0.tgz"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/once_1.1.0_1587421679230_0.7953557404424423"},"_hasShrinkwrap":false,"publish_time":1587421679335,"_cnpm_publish_time":1587421679335},"1.0.0":{"name":"@tootallnate/once","version":"1.0.0","description":"Creates a Promise that waits for a single event","main":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"prebuild":"rimraf dist","build":"tsc","test":"mocha --reporter spec","test-lint":"eslint src --ext .js,.ts","prepublishOnly":"npm run build"},"repository":{"type":"git","url":"git://github.com/TooTallNate/once.git"},"keywords":[],"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://n8.io/"},"license":"MIT","bugs":{"url":"https://github.com/TooTallNate/once/issues"},"devDependencies":{"@types/node":"^12.12.11","@typescript-eslint/eslint-plugin":"1.6.0","@typescript-eslint/parser":"1.1.0","eslint":"5.16.0","eslint-config-airbnb":"17.1.0","eslint-config-prettier":"4.1.0","eslint-import-resolver-typescript":"1.1.1","eslint-plugin-import":"2.16.0","eslint-plugin-jsx-a11y":"6.2.1","eslint-plugin-react":"7.12.4","mocha":"^6.2.2","rimraf":"^3.0.0","typescript":"^3.7.3"},"engines":{"node":">= 6"},"gitHead":"e3d8461b1bfa00b41329816f0caec8b9c7529158","homepage":"https://github.com/TooTallNate/once#readme","_id":"@tootallnate/once@1.0.0","_nodeVersion":"12.15.0","_npmVersion":"6.13.7","dist":{"shasum":"9c13c2574c92d4503b005feca8f2e16cc1611506","size":1444,"noattachment":false,"key":"/@tootallnate/once/-/@tootallnate/once-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@tootallnate/once/download/@tootallnate/once-1.0.0.tgz"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/once_1.0.0_1581205684926_0.4139655088212628"},"_hasShrinkwrap":false,"publish_time":1581205685016,"_cnpm_publish_time":1581205685016}},"readme":"# @tootallnate/once\n\n### Creates a Promise that waits for a single event\n\n## Installation\n\nInstall with `npm`:\n\n```bash\n$ npm install @tootallnate/once\n```\n\n## API\n\n### once(emitter: EventEmitter, name: string, opts?: OnceOptions): Promise&lt;[...Args]&gt;\n\nCreates a Promise that waits for event `name` to occur on `emitter`, and resolves\nthe promise with an array of the values provided to the event handler. If an\n`error` event occurs before the event specified by `name`, then the Promise is\nrejected with the error argument.\n\n```typescript\nimport once from '@tootallnate/once';\nimport { EventEmitter } from 'events';\n\nconst emitter = new EventEmitter();\n\nsetTimeout(() => {\n    emitter.emit('foo', 'bar');\n}, 100);\n\nconst [result] = await once(emitter, 'foo');\nconsole.log({ result });\n// { result: 'bar' }\n```\n\n#### Promise Strong Typing\n\nThe main feature that this module provides over other \"once\" implementations is that\nthe Promise that is returned is _**strongly typed**_ based on the type of `emitter`\nand the `name` of the event. Some examples are shown below.\n\n_The process \"exit\" event contains a single number for exit code:_\n\n```typescript\nconst [code] = await once(process, 'exit');\n//     ^ number\n```\n_A child process \"exit\" event contains either an exit code or a signal:_\n\n```typescript\nconst child = spawn('echo', []);\nconst [code, signal] = await once(child, 'exit');\n//     ^ number | null\n//           ^ string | null\n```\n\n_A forked child process \"message\" event is type `any`, so you can cast the Promise directly:_\n\n```typescript\nconst child = fork('file.js');\n\n// With `await`\nconst [message, _]: [WorkerPayload, unknown] = await once(child, 'message');\n\n// With Promise\nconst messagePromise: Promise<[WorkerPayload, unknown]> = once(child, 'message');\n\n// Better yet would be to leave it as `any`, and validate the payload\n// at runtime with i.e. `ajv` + `json-schema-to-typescript`\n```\n\n_If the TypeScript definition does not contain an overload for the specified event name, then the Promise will have type `unknown[]` and your code will need to narrow the result manually:_\n\n```typescript\ninterface CustomEmitter extends EventEmitter {\n    on(name: 'foo', listener: (a: string, b: number) => void): this;\n}\n\nconst emitter: CustomEmitter = new EventEmitter();\n\n// \"foo\" event is a defined overload, so it's properly typed\nconst fooPromise = once(emitter, 'foo');\n//    ^ Promise<[a: string, b: number]>\n\n// \"bar\" event in not a defined overload, so it gets `unknown[]`\nconst barPromise = once(emitter, 'bar');\n//    ^ Promise<unknown[]>\n```\n\n### OnceOptions\n\n-   `signal` - `AbortSignal` instance to unbind event handlers before the Promise has been fulfilled.\n","_attachments":{},"homepage":"https://github.com/TooTallNate/once#readme","bugs":{"url":"https://github.com/TooTallNate/once/issues"},"license":"MIT"}