<commit_before>/*
 * Author: CM
 */

(function(global) {

  /**
   * @callback PromiseThrottled
   * @param {*} any number of optional params
   * @return {Promise}
   */

  /**
   * @param {PromiseThrottled} fn
   * @param {Object|null} [options]
   * @param {Boolean} options.cancelLeading Whether to cancel the previous promise if it is still running.
   * @param {Boolean} options.queue Whether to queue the next promises.
   * @param {String} options.key A custom key to store the resulted PromiseThrottled.
   * @returns {PromiseThrottled}
   */
  function promiseThrottler(fn, options) {
    options = _.defaults(
      options || {}, {
        cancelLeading: false,
        queue: false
      }
    );
    if ((+options.cancelLeading) + (+options.queue) > 1) {
      throw new Error('PromiseThrottler options "cancelLeading", "queue" exclude each other.');
    }
    if (options.key) {
      return namespaceThrottler(options.key, fn, options);
    } else {
      return nonameThrottler(fn, options);
    }
  }

  /**
   * @see promiseThrottler
   */
  function nonameThrottler(fn, options) {
    var promise;

    return function() {
      if (options.cancelLeading && promise && promise.isPending() && promise.isCancellable()) {
        promise.cancel();
        promise = null;
      }
      if (options.queue && promise && promise.isPending()) {
        var args = arguments;
        var self = this;
        promise = promise.finally(function() {
          return fn.apply(self, args);
        });
      }
      if (!promise || !promise.isPending()) {
        promise = fn.apply(this, arguments);
      }
      return promise;
    };
  }

  var storage = {};
<commit_msg>Fix problem of async cancel call in PromiseThrottler<commit_after>/*
 * Author: CM
 */

(function(global) {

  /**
   * @callback PromiseThrottled
   * @param {*} any number of optional params
   * @return {Promise}
   */

  /**
   * @param {PromiseThrottled} fn
   * @param {Object|null} [options]
   * @param {Boolean} options.cancelLeading Whether to cancel the previous promise if it is still running.
   * @param {Boolean} options.queue Whether to queue the next promises.
   * @param {String} options.key A custom key to store the resulted PromiseThrottled.
   * @returns {PromiseThrottled}
   */
  function promiseThrottler(fn, options) {
    options = _.defaults(
      options || {}, {
        cancelLeading: false,
        queue: false
      }
    );
    if ((+options.cancelLeading) + (+options.queue) > 1) {
      throw new Error('PromiseThrottler options "cancelLeading", "queue" exclude each other.');
    }
    if (options.key) {
      return namespaceThrottler(options.key, fn, options);
    } else {
      return nonameThrottler(fn, options);
    }
  }

  /**
   * @see promiseThrottler
   */
  function nonameThrottler(fn, options) {
    var promise;

    return function() {
      var cancelLeading = options.cancelLeading && promise && promise.isPending() && promise.isCancellable();
      if (cancelLeading) {
        promise.cancel();
      }
      var addToQueue = options.queue && promise && promise.isPending();
      if (cancelLeading || addToQueue) {
        var args = arguments;
        var self = this;
        var leadingPromise = promise;
        promise = new Promise(function(resolve) {
          leadingPromise.finally(function() {
            resolve(fn.apply(self, args));
          });
        });
        return promise;
      }
      if (!promise || !promise.isPending()) {
        promise = fn.apply(this, arguments);
      }
      return promise;
    };
  }

  var storage = {};

{'fraction_non_alphanumeric': 0.1276005547850208, 'fraction_numerical': 0.0005547850208044383, 'mean_word_length': 2.521484375, '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': '1690970', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1086, 'n_words': 280}