<commit_before>class ConditionalPromise {
  /**
   * Create a conditional promise - like a promise, but cancelable!
   */
  constructor(...args) {
    if ([...args].length) {
      this._promise = new Promise(...args);
    }
  }

  catch(...args) {
    this._promise.catch(...args);
    return this;
  }

  then(...args) {
    this._promise.then(...args);
    return this;
  }

  only(cancelCheck, resolve, reject) {
    /*
     * When the promise resolves, call the resolve function, only if cancelCheck evaluates to true.
     * @param {cancelCheck} Function - Function that returns a Boolean.
     * @param {resolve} Function - Function to call if the Promise succeeds.
     * @param {reject} Function - Function to call if the Promise fails.
     */
    this._promise.then((success) => {
      if (cancelCheck() && resolve) {
        resolve(success);
      }
    }, (error) => {
      if (cancelCheck() && reject) {
        reject(error);
      }
    });
    return this;
  }

  static all(promises) {
    /*
     * Equivalent of Promise.all, but return a ConditionalPromise instead.
     * @param {promises} [Promise|ConditionalPromise] - an array of Promises
     */
    const conditionalPromise = new ConditionalPromise();
    conditionalPromise._promise = Promise.all(promises);
    return conditionalPromise;
  }
}

module.exports = ConditionalPromise;<commit_msg>Clean up semantics of ConditionalPromises.<commit_after>class ConditionalPromise {
  /**
   * Create a conditional promise - like a promise, but with an additional method 'only'
   * that allows for chaining resolve/reject handlers that will only be called if a
   * certain condition pertains.
   */
  constructor(...args) {
    if ([...args].length) {
      this._promise = new Promise(...args);
    }
  }

  catch(...args) {
    this._promise.catch(...args);
    return this;
  }

  then(...args) {
    this._promise.then(...args);
    return this;
  }

  only(continueCheck, resolve, reject) {
    /*
     * When the promise resolves, call resolve function, only if continueCheck evaluates to true.
     * @param {continueCheck} Function - Function that returns a Boolean,
     * @param {resolve} Function - Function to call if the Promise succeeds.
     * @param {reject} Function - Function to call if the Promise fails.
     */
    this._promise.then((success) => {
      if (continueCheck() && resolve) {
        resolve(success);
      }
    }, (error) => {
      if (continueCheck() && reject) {
        reject(error);
      }
    });
    return this;
  }

  static all(promises) {
    /*
     * Equivalent of Promise.all, but return a ConditionalPromise instead.
     * @param {promises} [Promise|ConditionalPromise] - an array of Promises
     */
    const conditionalPromise = new ConditionalPromise();
    conditionalPromise._promise = Promise.all(promises);
    return conditionalPromise;
  }
}

module.exports = ConditionalPromise;
{'fraction_non_alphanumeric': 0.12393016090380007, 'fraction_numerical': 0.0, 'mean_word_length': 2.6433915211970076, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6336217', 'n_tokens_mistral': 853, 'n_tokens_neox': 825, 'n_words': 240}