Readable.once method | Node.js stream module | Bun
BuildDocsReferenceGuidesBlogDiscord/
node:stream/
default/
Readable/
onceMonce
Search the reference...
/
BuildDocsReferenceGuidesBlogDiscord/
node:stream/
default/
Readable/
onceMonce
method
stream.default.Readable.once {
console.log('Ah, we have our first user!');
});
```
Returns a reference to the `EventEmitter`, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The
`emitter.prependOnceListener()` method can be used as an alternative to add the
event listener to the beginning of the listeners array.
```js
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
```" data-algolia-static="false" data-algolia-merged="false" data-type="Method">
onceE extends keyof
ReadableEventMap>(eventName: E,listener: (...args:
ReadableEventMap[E]) => void): this;
Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
@param eventName
The name of the event.
@param listener
The callback function
once(eventName: string | symbol,listener: (...args: any[]) => void): this;
Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlog Toolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →