Commit 6c0fe719 authored by Boris Kocherov's avatar Boris Kocherov

native Promise used if avalable as async core

parent e0d98b1c
...@@ -3,6 +3,29 @@ var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.We ...@@ -3,6 +3,29 @@ var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.We
var async; var async;
var local = (typeof global !== 'undefined') ? global : this; var local = (typeof global !== 'undefined') ? global : this;
function checkNativePromise() {
if (typeof Promise === "function" &&
typeof Promise.resolve === "function") {
try {
/* global Promise */
var promise = new Promise(function(){});
if ({}.toString.call(promise) === "[object Promise]") {
return true;
}
} catch (e) {}
}
return false;
}
function useNativePromise() {
var nativePromise = Promise.resolve();
return function(callback, arg) {
nativePromise.then(function () {
callback(arg);
});
};
}
// old node // old node
function useNextTick() { function useNextTick() {
return function(callback, arg) { return function(callback, arg) {
...@@ -58,7 +81,9 @@ function useSetTimeout() { ...@@ -58,7 +81,9 @@ function useSetTimeout() {
}; };
} }
if (typeof setImmediate === 'function') { if (checkNativePromise()) {
async = useNativePromise();
} else if (typeof setImmediate === 'function') {
async = useSetImmediate(); async = useSetImmediate();
} else if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') { } else if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
async = useNextTick(); async = useNextTick();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment