Gathering detailed insights and metrics for @tootallnate/once
Gathering detailed insights and metrics for @tootallnate/once
Gathering detailed insights and metrics for @tootallnate/once
Gathering detailed insights and metrics for @tootallnate/once
npm install @tootallnate/once
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
25 Stars
20 Commits
5 Forks
2 Watchers
1 Branches
3 Contributors
Updated on May 28, 2025
Latest Version
3.0.0
Package Id
@tootallnate/once@3.0.0
Size
4.34 kB
NPM Version
6.14.15
Node Version
12.22.6
Published on
Sep 27, 2021
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
7
Install with npm
:
1$ npm install @tootallnate/once
Creates a Promise that waits for event name
to occur on emitter
, and resolves
the promise with an array of the values provided to the event handler. If an
error
event occurs before the event specified by name
, then the Promise is
rejected with the error argument.
1import once from '@tootallnate/once'; 2import { EventEmitter } from 'events'; 3 4const emitter = new EventEmitter(); 5 6setTimeout(() => { 7 emitter.emit('foo', 'bar'); 8}, 100); 9 10const [result] = await once(emitter, 'foo'); 11console.log({ result }); 12// { result: 'bar' }
The main feature that this module provides over other "once" implementations is that
the Promise that is returned is strongly typed based on the type of emitter
and the name
of the event. Some examples are shown below.
The process "exit" event contains a single number for exit code:
1const [code] = await once(process, 'exit'); 2// ^ number
A child process "exit" event contains either an exit code or a signal:
1const child = spawn('echo', []); 2const [code, signal] = await once(child, 'exit'); 3// ^ number | null 4// ^ string | null
A forked child process "message" event is type any
, so you can cast the Promise directly:
1const child = fork('file.js'); 2 3// With `await` 4const [message, _]: [WorkerPayload, unknown] = await once(child, 'message'); 5 6// With Promise 7const messagePromise: Promise<[WorkerPayload, unknown]> = once(child, 'message'); 8 9// Better yet would be to leave it as `any`, and validate the payload 10// at runtime with i.e. `ajv` + `json-schema-to-typescript`
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:
1interface CustomEmitter extends EventEmitter { 2 on(name: 'foo', listener: (a: string, b: number) => void): this; 3} 4 5const emitter: CustomEmitter = new EventEmitter(); 6 7// "foo" event is a defined overload, so it's properly typed 8const fooPromise = once(emitter, 'foo'); 9// ^ Promise<[a: string, b: number]> 10 11// "bar" event in not a defined overload, so it gets `unknown[]` 12const barPromise = once(emitter, 'bar'); 13// ^ Promise<unknown[]>
signal
- AbortSignal
instance to unbind event handlers before the Promise has been fulfilled.No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 2/20 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More