2 // Use the fastest possible means to execute a task in a future turn
5 // linked list of tasks (single, with head node)
6 var head = {task: void 0, next: null};
9 var requestFlush = void 0;
13 /* jshint loopfunc: true */
19 var domain = head.domain;
31 // In node, uncaught exceptions are considered fatal errors.
32 // Re-throw them synchronously to interrupt flushing!
34 // Ensure continuation if the uncaught exception is suppressed
35 // listening "uncaughtException" events (as domains does).
36 // Continue in next event to avoid tick recursion.
48 // In browsers, uncaught exceptions are not fatal.
49 // Re-throw them asynchronously to avoid slow-downs.
50 setTimeout(function() {
64 if (typeof process !== "undefined" && process.nextTick) {
65 // Node.js before 0.9. Note that some fake-Node environments, like the
66 // Mocha test runner, introduce a `process` global without a `nextTick`.
69 requestFlush = function () {
70 process.nextTick(flush);
73 } else if (typeof setImmediate === "function") {
74 // In IE10, Node.js 0.9+, or https://github.com/NobleJS/setImmediate
75 if (typeof window !== "undefined") {
76 requestFlush = setImmediate.bind(window, flush);
78 requestFlush = function () {
83 } else if (typeof MessageChannel !== "undefined") {
85 // http://www.nonblocking.io/2011/06/windownexttick.html
86 var channel = new MessageChannel();
87 channel.port1.onmessage = flush;
88 requestFlush = function () {
89 channel.port2.postMessage(0);
94 requestFlush = function () {
102 domain: isNodeJS && process.domain,
112 module.exports = asap;