<commit_before><commit_msg>Introduce Queue for processing promisified functions in series<commit_after>import Orbit from 'orbit/core';

var Queue = function() {
  this.queue = [];
  this.processing = false;
};

Queue.prototype = {
  constructor: Queue,

  push: function(fn, binding) {
    var _this = this;

    binding = binding || this;

    if (this.processing) {
      debugger;
      var response = new Orbit.Promise(function(resolve) {
        _this.queue.push(function() {
          resolve(fn.call(binding));
        });
      });

      _this.process();

    } else {
      return fn.call(binding);
    }

    return response;
  },

  process: function() {
    if (!this.processing) {
      var _this = this;

      var settleEach = function() {
        if (_this.queue.length === 0) {
          _this.processing = false;

        } else {
          var fn = _this.queue.shift();
          var response = fn.call(_this);

          if (response) {
            return response.then(
              function(success) {
                settleEach();
              },
              function(error) {
                settleEach();
              }
            );
          } else {
            settleEach();
          }
        }
      };

      settleEach();
    }
  }
};

export default Queue;
{'fraction_non_alphanumeric': 0.12403697996918336, 'fraction_numerical': 0.0007704160246533128, 'mean_word_length': 1.6242424242424243, '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': '5969300', 'n_tokens_mistral': 378, 'n_tokens_neox': 366, 'n_words': 80}