Mitt Async #157
developit
announced in
Announcements
Mitt Async
#157
Replies: 1 comment
-
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)))
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 normalemit()
method:Beta Was this translation helpful? Give feedback.
All reactions