Shogun
Shogun

Reputation: 138

Wait until all event listeners done

So once called, an event emitter loses any control of what event listeners are doing and how long they will run. But what if we need to do next thing only after all event listeners complete they work? How can I know when they have completed their work?

One solution could be to get listeners from EventEmitter.listeners() and call them in parallel with async or something like this, but this is not that great at all. ((

Any nice solution for this?

Upvotes: 4

Views: 1485

Answers (1)

mtsr
mtsr

Reputation: 3142

If you are only interested in synchronous code executed by the event-listeners, you can simply add an event-listener to the list, which should be called last.

If not... maybe you can have each of the event-listeners call a callback when done?

Upvotes: 1

Related Questions