Sha256: 031b19a64632cc2ac4fabb72958098126af95a30145b9ee522f6ae75ff14deb4

Contents?: true

Size: 1.94 KB

Versions: 60

Compression:

Stored size: 1.94 KB

Contents

var global = require('./_global');
var macrotask = require('./_task').set;
var Observer = global.MutationObserver || global.WebKitMutationObserver;
var process = global.process;
var Promise = global.Promise;
var isNode = require('./_cof')(process) == 'process';

module.exports = function () {
  var head, last, notify;

  var flush = function () {
    var parent, fn;
    if (isNode && (parent = process.domain)) parent.exit();
    while (head) {
      fn = head.fn;
      head = head.next;
      try {
        fn();
      } catch (e) {
        if (head) notify();
        else last = undefined;
        throw e;
      }
    } last = undefined;
    if (parent) parent.enter();
  };

  // Node.js
  if (isNode) {
    notify = function () {
      process.nextTick(flush);
    };
  // browsers with MutationObserver, except iOS Safari - https://github.com/zloirock/core-js/issues/339
  } else if (Observer && !(global.navigator && global.navigator.standalone)) {
    var toggle = true;
    var node = document.createTextNode('');
    new Observer(flush).observe(node, { characterData: true }); // eslint-disable-line no-new
    notify = function () {
      node.data = toggle = !toggle;
    };
  // environments with maybe non-completely correct, but existent Promise
  } else if (Promise && Promise.resolve) {
    // Promise.resolve without an argument throws an error in LG WebOS 2
    var promise = Promise.resolve(undefined);
    notify = function () {
      promise.then(flush);
    };
  // for other environments - macrotask based on:
  // - setImmediate
  // - MessageChannel
  // - window.postMessag
  // - onreadystatechange
  // - setTimeout
  } else {
    notify = function () {
      // strange IE + webpack dev server bug - use .call(global)
      macrotask.call(global, flush);
    };
  }

  return function (fn) {
    var task = { fn: fn, next: undefined };
    if (last) last.next = task;
    if (!head) {
      head = task;
      notify();
    } last = task;
  };
};

Version data entries

60 entries across 27 versions & 6 rubygems

Version Path
immosquare-cleaner-0.1.52 node_modules/core-js/modules/_microtask.js
immosquare-cleaner-0.1.52 node_modules/core-js/library/modules/_microtask.js
immosquare-cleaner-0.1.51 node_modules/core-js/library/modules/_microtask.js
immosquare-cleaner-0.1.51 node_modules/core-js/modules/_microtask.js
immosquare-cleaner-0.1.50 node_modules/core-js/library/modules/_microtask.js
immosquare-cleaner-0.1.50 node_modules/core-js/modules/_microtask.js
immosquare-cleaner-0.1.49 node_modules/core-js/library/modules/_microtask.js
immosquare-cleaner-0.1.49 node_modules/core-js/modules/_microtask.js
immosquare-cleaner-0.1.48 node_modules/core-js/library/modules/_microtask.js
immosquare-cleaner-0.1.48 node_modules/core-js/modules/_microtask.js
immosquare-cleaner-0.1.47 node_modules/core-js/library/modules/_microtask.js
immosquare-cleaner-0.1.47 node_modules/core-js/modules/_microtask.js
immosquare-cleaner-0.1.46 node_modules/core-js/library/modules/_microtask.js
immosquare-cleaner-0.1.46 node_modules/core-js/modules/_microtask.js
immosquare-cleaner-0.1.45 node_modules/core-js/library/modules/_microtask.js
immosquare-cleaner-0.1.45 node_modules/core-js/modules/_microtask.js
immosquare-cleaner-0.1.44 node_modules/core-js/library/modules/_microtask.js
immosquare-cleaner-0.1.44 node_modules/core-js/modules/_microtask.js
immosquare-cleaner-0.1.43 node_modules/core-js/library/modules/_microtask.js
immosquare-cleaner-0.1.43 node_modules/core-js/modules/_microtask.js