setImmediate.js 857 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.fallback = fallback;
  6. exports.wrap = wrap;
  7. /* istanbul ignore file */
  8. var hasQueueMicrotask = exports.hasQueueMicrotask = typeof queueMicrotask === 'function' && queueMicrotask;
  9. var hasSetImmediate = exports.hasSetImmediate = typeof setImmediate === 'function' && setImmediate;
  10. var hasNextTick = exports.hasNextTick = typeof process === 'object' && typeof process.nextTick === 'function';
  11. function fallback(fn) {
  12. setTimeout(fn, 0);
  13. }
  14. function wrap(defer) {
  15. return (fn, ...args) => defer(() => fn(...args));
  16. }
  17. var _defer;
  18. if (hasQueueMicrotask) {
  19. _defer = queueMicrotask;
  20. } else if (hasSetImmediate) {
  21. _defer = setImmediate;
  22. } else if (hasNextTick) {
  23. _defer = process.nextTick;
  24. } else {
  25. _defer = fallback;
  26. }
  27. exports.default = wrap(_defer);