<commit_before>module.exports = createFuture;

// avoid nextTick recursion by grouping every
// callback that needs to be run, under the same
// nextTick
var nextTickHandlers = [];
function next(fn) {

  if (!nextTickHandlers.length) {
    process.nextTick(function() {
      while (nextTickHandlers.length) {
        nextTickHandlers.pop()();
      }
    });
  }

  nextTickHandlers.push(fn);
}

function createFuture() {
  var watchers = [];
  var value = null;
  var error = null;
  var resolved = false;

  function notifyWatchers() {
    while (watchers.length) {
      watchers.pop()(error, value);
    }
    resolved = true;
  }

  function future(e, r) {
    if (typeof e === 'function') {
      if (resolved) {
        e(error, value)
      } else {
        watchers.push(e);
      }
    } else {
      error = e;
      value = r;

      next(notifyWatchers);
    }

    // enable "chaining"
    return future;
  }

  future.isFuture = true;

  return future;
}<commit_msg>make observers fifo<commit_after>module.exports = createFuture;

// avoid nextTick recursion by grouping every
// callback that needs to be run, under the same
// nextTick
var nextTickHandlers = [];
function next(fn) {

  if (!nextTickHandlers.length) {
    process.nextTick(function() {
      while (nextTickHandlers.length) {
        nextTickHandlers.shift()();
      }
    });
  }

  nextTickHandlers.push(fn);
}

function createFuture() {
  var watchers = [];
  var value = null;
  var error = null;
  var resolved = false;

  function notifyWatchers() {
    while (watchers.length) {
      watchers.shift()(error, value);
    }
    resolved = true;
  }

  function future(e, r) {
    if (typeof e === 'function') {
      if (resolved) {
        e(error, value)
      } else {
        watchers.push(e);
      }
    } else {
      error = e;
      value = r;

      next(notifyWatchers);
    }

    // enable "chaining"
    return future;
  }

  future.isFuture = true;

  return future;
}
{'fraction_non_alphanumeric': 0.1286727456940223, 'fraction_numerical': 0.0, 'mean_word_length': 2.3993115318416525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '607900', 'n_tokens_mistral': 649, 'n_tokens_neox': 626, 'n_words': 156}