nextTick.js 478 B

123456789101112131415161718
  1. if (typeof process === 'object' && process.nextTick && !false) {
  2. exports = process.nextTick;
  3. } else if (typeof setImmediate === 'function') {
  4. exports = function(cb) {
  5. setImmediate(ensureCallable(cb));
  6. };
  7. } else {
  8. exports = function(cb) {
  9. setTimeout(ensureCallable(cb), 0);
  10. };
  11. }
  12. function ensureCallable(fn) {
  13. if (typeof fn !== 'function')
  14. throw new TypeError(fn + ' is not a function');
  15. return fn;
  16. }
  17. module.exports = exports;