diff options
author | Caolan McMahon <caolan@caolanmcmahon.com> | 2013-01-31 14:05:47 +0000 |
---|---|---|
committer | Caolan McMahon <caolan@caolanmcmahon.com> | 2013-01-31 14:05:47 +0000 |
commit | d87f799cc0dcf8b8248ce726ee8b0fabdcf93566 (patch) | |
tree | 575045a1da977a2ff15b978ab41bb6c443c31f01 | |
parent | 8ff697f254cc0fcbeecb2bee1fb329c71860fc24 (diff) | |
parent | 4ef2984463de6fcc5685ebaf680db02a01587b97 (diff) | |
download | async-d87f799cc0dcf8b8248ce726ee8b0fabdcf93566.tar.gz |
Merge remote branch 'dougwilson/feature/setImmediate-support'
Conflicts:
dist/async.min.js
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | lib/async.js | 15 |
2 files changed, 14 insertions, 6 deletions
@@ -1067,8 +1067,9 @@ three ### nextTick(callback) Calls the callback on a later loop around the event loop. In node.js this just -calls process.nextTick, in the browser it falls back to setTimeout(callback, 0), -which means other higher priority events may precede the execution of the callback. +calls process.nextTick, in the browser it falls back to setImmediate(callback) +if available, otherwise setTimeout(callback, 0), which means other higher priority +events may precede the execution of the callback. This is used internally for browser-compatibility purposes. diff --git a/lib/async.js b/lib/async.js index b3c25d6..4185b11 100644 --- a/lib/async.js +++ b/lib/async.js @@ -1,4 +1,4 @@ -/*global setTimeout: false, console: false */ +/*global setImmediate: false, setTimeout: false, console: false */ (function () { var async = {}; @@ -74,9 +74,16 @@ //// nextTick implementation with browser-compatible fallback //// if (typeof process === 'undefined' || !(process.nextTick)) { - async.nextTick = function (fn) { - setTimeout(fn, 0); - }; + if (typeof setImmediate === 'function') { + async.nextTick = function (fn) { + setImmediate(fn); + }; + } + else { + async.nextTick = function (fn) { + setTimeout(fn, 0); + }; + } } else { async.nextTick = process.nextTick; |