3 ms·
It's a bit out of fashion, but same thing can be achieved without any extra code using a built-in EventEmitter: let channel = new EventEmitter() await
by ricardobeat 4y ago
It's a bit out of fashion, but same thing can be achieved without any extra code using a built-in EventEmitter:
let channel = new EventEmitter()
await Promise.all([
compile.browser(channel),
compile.server(channel)
])
// in compile.browser
channel.emit("manifest", assetsManifest)
// in compile.server
channel.once("manifest", (assetsManifest) => ... )
A new emitter is used each time, so the end result is the same. Curious to hear what others think.
- minitech 4y agoEventEmitter doesn’t hold on to its values, so if the `channel.once` listener doesn’t get attached before `emit` is called, the value will be missed. Also, in order to wait on an event, you usually end up with a promise anyway (so `await` can be used).
- deleted 4y ago[deleted]