function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/**
 * Barrier is just a Promise which has resolve and reject exposed as instance
 * methods.
 *
 * The implementation is adopted from `@dr.pogodin/react-utils`, with private
 * fields replaced by underscore-prefixed public fields to avoid issues with
 * React Native, for which see:
 * https://github.com/birdofpreyru/react-native-static-server/issues/6
 * https://github.com/birdofpreyru/react-native-static-server/issues/9
 *
 * Docs: https://dr.pogodin.studio/docs/react-utils/docs/api/classes/Barrier
 */
export class Barrier extends Promise {
  constructor(executor) {
    let resolveRef;
    let rejectRef;
    super((resolve, reject) => {
      resolveRef = value => {
        resolve(value);
        this._resolved = true;
      };

      rejectRef = error => {
        reject(error);
        this._rejected = true;
      };

      if (executor) executor(resolveRef, rejectRef);
    });

    _defineProperty(this, "_resolve", void 0);

    _defineProperty(this, "_resolved", false);

    _defineProperty(this, "_reject", void 0);

    _defineProperty(this, "_rejected", false);

    this._resolve = resolveRef;
    this._reject = rejectRef;
  }

  get resolve() {
    return this._resolve;
  }

  get resolved() {
    return this._resolved;
  }

  get reject() {
    return this._reject;
  }

  get rejected() {
    return this._rejected;
  }

  then(onFulfilled, onRejected) {
    const res = super.then(onFulfilled, onRejected);
    res._resolve = this._resolve;
    res._reject = this._reject;
    return res;
  }

}
//# sourceMappingURL=Barrier.js.map