0

As it follows from the documentation, Node.js EventEmitter calls its listeneres synchronously.

const emitter = new EventEmitter();
emitter.on('event', async (e) => {
  await sendData(e);
  updateUI();
});

Considering this code, one can make a reasonable guess of whenever sendData() be overly delayed, a promise returned from the async callback may be collected, so updateUI() will never get executed. Does this guess has any ground?

There is also currently experimental capture rejections of promises api which enables to receive notifications of promises rejections (through error event). Does it mean in this case an EventEmitter instance keeps all promises references in the memory, therefore collecting is impossible?

Ilya Loskutov
  • 1,967
  • 2
  • 20
  • 34

1 Answers1

0

"Node.js EventEmitter calls its listeneres synchronously."

Sure, but that does not mean the contents of said listeners can't be async.

Since that assertion is false, logically, await will wait indefinitely.

Cerbrus
  • 70,800
  • 18
  • 132
  • 147