You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

defer.js 441B

1234567891011121314151617181920212223242526
  1. module.exports = defer;
  2. /**
  3. * Runs provided function on next iteration of the event loop
  4. *
  5. * @param {function} fn - function to run
  6. */
  7. function defer(fn)
  8. {
  9. var nextTick = typeof setImmediate == 'function'
  10. ? setImmediate
  11. : (
  12. typeof process == 'object' && typeof process.nextTick == 'function'
  13. ? process.nextTick
  14. : null
  15. );
  16. if (nextTick)
  17. {
  18. nextTick(fn);
  19. }
  20. else
  21. {
  22. setTimeout(fn, 0);
  23. }
  24. }