What is ee-first?
The ee-first package is a utility for Node.js that allows you to wait for multiple EventEmitter or Stream instances to emit an event or error and then execute a callback. It is particularly useful when you need to listen for an event from multiple sources and want to take action only after the first one occurs.
Listening for the first event or error from multiple emitters
This feature allows you to pass an array of arrays, where each sub-array contains an EventEmitter instance followed by one or more event names. The callback function is then executed when the first event from any of the listed emitters is emitted.
const first = require('ee-first');
const stream1 = getSomeReadableStream();
const stream2 = getAnotherReadableStream();
const thunk = first([
[stream1, 'end', 'error'],
[stream2, 'end', 'error']
], function (err, ee, event, args) {
// This function will be called when one of the streams emits 'end' or 'error'
// `ee` is the event emitter that fired
// `event` is the string name of the event that fired
// `args` is an array of the arguments that were passed to the event
});