- Notifications
You must be signed in to change notification settings - Fork2.9k
Description
In talking with the Angular team (mostly@mhevery), there is interest in a simple low-level method for enqueuing a microtask from author code. I've heard this from a number of authors in the past. It seems simple enough and easy to add to the spec, if we can get any other implementations besides Chrome interested.
Right now authors are doing this via a number ofhacks, like creating a text node and a MutationObserver and twiddling the text node every time they want to trigger a microtask, or usingPromise.resolve().then(f)
(which creates a promise object and stores any thrown errors there, instead of letting them propagate to "report an exception").
There are many use cases, which I'm sure we can assemble in depth, but let me just start with the following reasons which will hopefully be enough to convince people:
- From an academic point of view, this is a low-level primitive and there's no reason to lock it up behind higher-level concepts like promises and mutation observers.
- From a practical point of view, libraries very often want to guarantee asynchrony (toavoid Zalgo), without taking the overhead of a full "macro" task like
setTimeout(f, 0)
.
I'd like to first focus this thread on finding implementer support: if we spec this, will you implement it?After that, we can start bikeshedding the name; please don't do so beforehand.
/ccing some implementers:@hober@travisleithead@bzbarsky