import { __require as h } from "./index-CanceledError.js";
var c, a;
function p() {
  if (a) return c;
  a = 1;
  var f = h();
  function i(s) {
    if (typeof s != "function")
      throw new TypeError("executor must be a function.");
    var r;
    this.promise = new Promise(function(n) {
      r = n;
    });
    var e = this;
    this.promise.then(function(t) {
      if (e._listeners) {
        for (var n = e._listeners.length; n-- > 0; )
          e._listeners[n](t);
        e._listeners = null;
      }
    }), this.promise.then = function(t) {
      var n, u = new Promise(function(o) {
        e.subscribe(o), n = o;
      }).then(t);
      return u.cancel = function() {
        e.unsubscribe(n);
      }, u;
    }, s(function(n, u, o) {
      e.reason || (e.reason = new f(n, u, o), r(e.reason));
    });
  }
  return i.prototype.throwIfRequested = function() {
    if (this.reason)
      throw this.reason;
  }, i.prototype.subscribe = function(r) {
    if (this.reason) {
      r(this.reason);
      return;
    }
    this._listeners ? this._listeners.push(r) : this._listeners = [r];
  }, i.prototype.unsubscribe = function(r) {
    if (this._listeners) {
      var e = this._listeners.indexOf(r);
      e !== -1 && this._listeners.splice(e, 1);
    }
  }, i.source = function() {
    var r, e = new i(function(n) {
      r = n;
    });
    return {
      token: e,
      cancel: r
    };
  }, c = i, c;
}
export {
  p as __require
};
