<commit_before>const handleCallback = (resolve, reject, callback, r) => {
  try {
    resolve(callback(r));
  } catch (e) {
    reject(e);
  }
};

export default class CancelablePromise {
  static all(iterable) {
    return new CancelablePromise((y, n) => {
      Promise.all(iterable).then(y, n);
    });
  }

  static race(iterable) {
    return new CancelablePromise((y, n) => {
      Promise.race(iterable).then(y, n);
    });
  }

  static reject(value) {
    return new CancelablePromise((y, n) => {
      Promise.reject(value).then(y, n);
    });
  }

  static resolve(value) {
    return new CancelablePromise((y, n) => {
      Promise.resolve(value).then(y, n);
    });
  }

  constructor(executor) {
    this._promise = new Promise(executor);
    this._canceled = false;
  }

  then(success, error) {
    const p = new CancelablePromise((resolve, reject) => {
      this._promise.then((r) => {
        if (this._canceled) {
          p.cancel();
        }
        if (success && !this._canceled) {
          handleCallback(resolve, reject, success, r);
        } else {
          resolve(r);
        }
      }, (r) => {
        if (this._canceled) {
          p.cancel();
        }
        if (error && !this._canceled) {
          handleCallback(resolve, reject, error, r);
        } else {
          reject(r);
        }
      });
    });
    return p;
  }

  catch(error) {
    return this.then(undefined, error);
  }

  cancel(errorCallback) {
    this._canceled = true;
    if (error) {
      this._promise.catch(errorCallback);
    }
    return this;
  }
}<commit_msg>Fix: incorrect condition for error callback<commit_after>const handleCallback = (resolve, reject, callback, r) => {
  try {
    resolve(callback(r));
  } catch (e) {
    reject(e);
  }
};

export default class CancelablePromise {
  static all(iterable) {
    return new CancelablePromise((y, n) => {
      Promise.all(iterable).then(y, n);
    });
  }

  static race(iterable) {
    return new CancelablePromise((y, n) => {
      Promise.race(iterable).then(y, n);
    });
  }

  static reject(value) {
    return new CancelablePromise((y, n) => {
      Promise.reject(value).then(y, n);
    });
  }

  static resolve(value) {
    return new CancelablePromise((y, n) => {
      Promise.resolve(value).then(y, n);
    });
  }

  constructor(executor) {
    this._promise = new Promise(executor);
    this._canceled = false;
  }

  then(success, error) {
    const p = new CancelablePromise((resolve, reject) => {
      this._promise.then((r) => {
        if (this._canceled) {
          p.cancel();
        }
        if (success && !this._canceled) {
          handleCallback(resolve, reject, success, r);
        } else {
          resolve(r);
        }
      }, (r) => {
        if (this._canceled) {
          p.cancel();
        }
        if (error && !this._canceled) {
          handleCallback(resolve, reject, error, r);
        } else {
          reject(r);
        }
      });
    });
    return p;
  }

  catch(error) {
    return this.then(undefined, error);
  }

  cancel(errorCallback) {
    this._canceled = true;
    if (errorCallback) {
      this._promise.catch(errorCallback);
    }
    return this;
  }
}
{'fraction_non_alphanumeric': 0.1543980037429819, 'fraction_numerical': 0.0, 'mean_word_length': 2.1752475247524754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '3667911', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1062, 'n_words': 205}