<commit_before>'use strict';

var Promise = require('es6-promise').Promise;

module.exports = function(array, haltCallback) {
  if(!(haltCallback instanceof Function)) {
    haltCallback = function() {
      return true;
    };
  }
  return new Promise(function(resolve, reject) {
    var i = 0,
      len = array.length,
      results = [];

    function processPromise(result) {
      results[i] = result;
      if(!haltCallback(result)) {
        return resolve(results);
      }
      i++;
      next();
    }

    function next() {
      if(i >= len) return resolve(results);

      var method = array[i];
      if(!(method instanceof Function)) {
        return processPromise(method);
      }

      var p = method();
      if((p instanceof Promise)) {
        p.then(processPromise).catch(reject);
      } else {
        processPromise(p);
      }
    }

    next();
  });
};<commit_msg>Allow more liberal promise detection, es5 compat<commit_after>'use strict';

var Promise = require('es6-promise').Promise;

module.exports = function(array, haltCallback) {
  if(!(haltCallback instanceof Function)) {
    haltCallback = function() {
      return true;
    };
  }
  return new Promise(function(resolve, reject) {
    var i = 0,
      len = array.length,
      results = [];

    function processPromise(result) {
      results[i] = result;
      if(!haltCallback(result)) {
        return resolve(results);
      }
      i++;
      next();
    }

    function next() {
      if(i >= len) return resolve(results);

      var method = array[i];
      if(typeof method !== 'function') {
        return processPromise(method);
      }

      var p = method();
      if(typeof p.then === 'function' && typeof p.catch === 'function') {
        p.then(processPromise).catch(reject);
      } else {
        processPromise(p);
      }
    }

    next();
  });
};
{'fraction_non_alphanumeric': 0.14439076757917338, 'fraction_numerical': 0.0026838432635534087, 'mean_word_length': 2.3646209386281587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5148388', 'n_tokens_mistral': 549, 'n_tokens_neox': 536, 'n_words': 125}