summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolan McMahon <caolan@caolanmcmahon.com>2013-01-31 14:05:47 +0000
committerCaolan McMahon <caolan@caolanmcmahon.com>2013-01-31 14:05:47 +0000
commitd87f799cc0dcf8b8248ce726ee8b0fabdcf93566 (patch)
tree575045a1da977a2ff15b978ab41bb6c443c31f01
parent8ff697f254cc0fcbeecb2bee1fb329c71860fc24 (diff)
parent4ef2984463de6fcc5685ebaf680db02a01587b97 (diff)
downloadasync-d87f799cc0dcf8b8248ce726ee8b0fabdcf93566.tar.gz
Merge remote branch 'dougwilson/feature/setImmediate-support'
Conflicts: dist/async.min.js
-rw-r--r--README.md5
-rw-r--r--lib/async.js15
2 files changed, 14 insertions, 6 deletions
diff --git a/README.md b/README.md
index 40b1c0f..5c3351b 100644
--- a/README.md
+++ b/README.md
@@ -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;