This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test('events', async() => { | |
const { EventEmitter } = require('events') | |
const ee = new EventEmitter() | |
const handler = (breadcrumb: string, delay: number) => | |
(promises: Promise<unknown>[]) => { | |
promises.push(new Promise(resolve => { | |
setTimeout(() => resolve(breadcrumb), delay) | |
})) | |
} | |
ee.on('thing', handler('a', 0) ) | |
ee.on('thing', handler('b', 100) ) | |
ee.on('thing', handler('c', 0) ) | |
ee.on('thing', handler('d', 3 * 1000) ) | |
const promises: Promise<unknown>[] = [] | |
ee.emit('thing', promises) | |
console.log({promises}, promises[0] instanceof Promise) | |
const results = await Promise.all(promises) | |
console.log({results}) | |
}) |
Author
dwelch2344
commented
Mar 4, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment