emitter{EventEmitter}eventName{string|symbol} The name of the event being listened for- Returns: {AsyncIterator} that iterates
eventNameevents emitted by theemitter
const { on, EventEmitter } = require('events');(async () => {const ee = new EventEmitter();// Emit later onprocess.nextTick(() => {ee.emit('foo', 'bar');ee.emit('foo', 42);});for await (const event of on(ee, 'foo')) {// The execution of this inner block is synchronous and it// processes one event at a time (even with await). Do not use// if concurrent execution is required.console.log(event); // prints ['bar'] [42]}// Unreachable here})();
Returns an AsyncIterator that iterates eventName events. It will throw
if the EventEmitter emits 'error'. It removes all listeners when
exiting the loop. The value returned by each iteration is an array
composed of the emitted event arguments.
