-
-
Notifications
You must be signed in to change notification settings - Fork 37.1k
Add async emit methods to EventEmitter #18646
Copy link
Copy link
Closed
Labels
eventsIssues and PRs related to EventEmitter and the events module.Issues and PRs related to EventEmitter and the events module.feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.
Description
Activity
Metadata
Metadata
Assignees
Labels
eventsIssues and PRs related to EventEmitter and the events module.Issues and PRs related to EventEmitter and the events module.feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.
Version:
v8.9.4
Platform:
Darwin pumba-5.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64
Subsystem:
events
https://nodejs.org/api/events.html#events_asynchronous_vs_synchronous instructs users to cause asynchronous event execution in the event handlers by using
setImmediateorprocess.nextTick, which means that, when usingEventEmitter#emit, asynchronous event handling is left to clients, and theEventEmitterhas no control over whether an event is handled asynchronously or synchronously. In cases where theEventEmitteris sensitive to performance, theEventEmitteritself can dictate the event emission is asynchronous via code similar to the following:The
emitline above could be replaced by something convenient likeor, even more conveniently,
which uses either
setImmediateorprocess.nextTickaccording to the current environment.