Sha256: a736ab3e296a0637d040603df55a5943d1f850e51c94f8595965c4875e307512

Contents?: true

Size: 1.84 KB

Versions: 16

Compression:

Stored size: 1.84 KB

Contents

'use strict';
var Mutation = global.MutationObserver || global.WebKitMutationObserver;

var scheduleDrain;

{
  if (Mutation) {
    var called = 0;
    var observer = new Mutation(nextTick);
    var element = global.document.createTextNode('');
    observer.observe(element, {
      characterData: true
    });
    scheduleDrain = function () {
      element.data = (called = ++called % 2);
    };
  } else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') {
    var channel = new global.MessageChannel();
    channel.port1.onmessage = nextTick;
    scheduleDrain = function () {
      channel.port2.postMessage(0);
    };
  } else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) {
    scheduleDrain = function () {

      // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
      // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
      var scriptEl = global.document.createElement('script');
      scriptEl.onreadystatechange = function () {
        nextTick();

        scriptEl.onreadystatechange = null;
        scriptEl.parentNode.removeChild(scriptEl);
        scriptEl = null;
      };
      global.document.documentElement.appendChild(scriptEl);
    };
  } else {
    scheduleDrain = function () {
      setTimeout(nextTick, 0);
    };
  }
}

var draining;
var queue = [];
//named nextTick for less confusing stack traces
function nextTick() {
  draining = true;
  var i, oldQueue;
  var len = queue.length;
  while (len) {
    oldQueue = queue;
    queue = [];
    i = -1;
    while (++i < len) {
      oldQueue[i]();
    }
    len = queue.length;
  }
  draining = false;
}

module.exports = immediate;
function immediate(task) {
  if (queue.push(task) === 1 && !draining) {
    scheduleDrain();
  }
}

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
UrgentcareCLI-0.1.1 node_modules/immediate/lib/browser.js
loco-rails-2.5.3 test/dummy/node_modules/immediate/lib/browser.js
loco-rails-2.5.2 test/dummy/node_modules/immediate/lib/browser.js
loco-rails-2.5.1 test/dummy/node_modules/immediate/lib/browser.js
loco-rails-2.5.0 test/dummy/node_modules/immediate/lib/browser.js
loco-rails-2.4.0 test/dummy/node_modules/immediate/lib/browser.js
loco-rails-2.3.0 test/dummy/node_modules/immediate/lib/browser.js
loco-rails-3.0.0 test/dummy/node_modules/immediate/lib/browser.js
loco-rails-2.2.2 test/dummy/node_modules/immediate/lib/browser.js
loco-rails-2.2.1 test/dummy/node_modules/immediate/lib/browser.js
loco-rails-2.2.0 test/dummy/node_modules/immediate/lib/browser.js
loco-rails-2.1.0 test/dummy/node_modules/immediate/lib/browser.js
loco-rails-2.0.0 test/dummy/node_modules/immediate/lib/browser.js
loco-rails-1.5.2 test/dummy/node_modules/immediate/lib/browser.js
loco-rails-1.5.1 test/dummy/node_modules/immediate/lib/browser.js
loco-rails-1.5.0 test/dummy/node_modules/immediate/lib/browser.js