| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
my proposal to maximize asynchronous capabilities: function emitAsync (type, data) {
const fns = []
.concat(this.emitter.all.get('*'))
.concat(this.emitter.all.get(type))
.filter(Boolean)
return Promise.all(fns.map(fn => fn(data)))
} |
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
{{title}}
Uh oh!
There was an error while loading. Please reload this page.
Q: Why doesn't Mitt support async event handlers? (from #122)
Asynchrony is expensive when unused, so it can't feasibly be landed in Mitt itself. Also, there isn't an obvious solution for how data should flow between handlers: a function being async implies it should have a return value (since async functions are just functions that return a Promise) - otherwise "async emit" is effectively "sequential emit" or a queue.
However you can implement it as an add-on. I'd recommend calling it emitAsync() or something, rather than overwriting the normal emit() method: