asap
asap copied to clipboard
Consider using Promise.prototype.then
There's a blog post about how using Promise.then
is supposedly even faster than .nextTick.
Given that we have stuff like io.js with Promise support and a lot of browser supporting it to, do you think it'd make sense to conditionally use this feature if it exists?
We need to be a little careful with polyfills for Promise that use this library internally.
Yeah, there could be something like this code to check that the Promise implementation is indeed native:
if(typeof Promise !== "undefined" && Promise.toString().indexOf("[native code]") !== -1){
// it's native
}
Shamelessly grabbed from Benjamin Gruenbaum
FYI, there seems to be a bug in Firefox microtask scheduling using a resolved Promise, see https://bugzilla.mozilla.org/show_bug.cgi?id=1162013
On Chrome, Promise
does not seem be faster than MutationObserver
.