nextTick.js
1 'use strict'; 2 /* istanbul ignore file */ 3 4 Object.defineProperty(exports, "__esModule", { 5 value: true 6 }); 7 8 var _setImmediate = require('./internal/setImmediate'); 9 10 /** 11 * Calls `callback` on a later loop around the event loop. In Node.js this just 12 * calls `process.nextTick`. In the browser it will use `setImmediate` if 13 * available, otherwise `setTimeout(callback, 0)`, which means other higher 14 * priority events may precede the execution of `callback`. 15 * 16 * This is used internally for browser-compatibility purposes. 17 * 18 * @name nextTick 19 * @static 20 * @memberOf module:Utils 21 * @method 22 * @see [async.setImmediate]{@link module:Utils.setImmediate} 23 * @category Util 24 * @param {Function} callback - The function to call on a later loop around 25 * the event loop. Invoked with (args...). 26 * @param {...*} args... - any number of additional arguments to pass to the 27 * callback on the next tick. 28 * @example 29 * 30 * var call_order = []; 31 * async.nextTick(function() { 32 * call_order.push('two'); 33 * // call_order now equals ['one','two'] 34 * }); 35 * call_order.push('one'); 36 * 37 * async.setImmediate(function (a, b, c) { 38 * // a, b, and c equal 1, 2, and 3 39 * }, 1, 2, 3); 40 */ 41 var _defer; 42 43 if (_setImmediate.hasNextTick) { 44 _defer = process.nextTick; 45 } else if (_setImmediate.hasSetImmediate) { 46 _defer = setImmediate; 47 } else { 48 _defer = _setImmediate.fallback; 49 } 50 51 exports.default = (0, _setImmediate.wrap)(_defer); 52 module.exports = exports['default'];