-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Closed
Labels
docIssues and PRs related to the documentations.Issues and PRs related to the documentations.eventsIssues and PRs related to the events subsystem / EventEmitter.Issues and PRs related to the events subsystem / EventEmitter.
Description
The documentation for once states:
Creates a Promise that is fulfilled when the EventEmitter emits the given event or that is rejected when the EventEmitter emits 'error'. The Promise will resolve with an array of all the arguments emitted to the given event.
It's not clear from the documentation what happens when once is used to listen for error event. In my case this is the desired behaviors but I was surprised when my tests were not failing because an error event was emitted.
This:
const { EventEmitter, once } = require('events');
const ee = new EventEmitter();
once(ee, 'error').then(([err]) => {
console.log('resolves', err);
}).catch((err) => {
console.log('rejects', err);
})
ee.emit('error', new Error('Hi'))Prints:
resolves Error: Hi
at Object.<anonymous> ...
Can you clarify this behaviour in the documentation please?
Metadata
Metadata
Assignees
Labels
docIssues and PRs related to the documentations.Issues and PRs related to the documentations.eventsIssues and PRs related to the events subsystem / EventEmitter.Issues and PRs related to the events subsystem / EventEmitter.