const o = (f) => {
  throw f;
}, a = () => {
};
class c {
  subscriber;
  /**
   * Creates an Observable with a subscriber function.
   *
   * This subscriber function receives an Observer object
   * in which is used to execute the actual subscription
   * logic.
   *
   * The purpose of this is to not repeatedly create
   * the subscription object.
   */
  constructor(r) {
    this.subscriber = r;
  }
  /**
   * Provides an API (via a cold Observable) that bridges
   * the reactive world with the callback-style world.
   */
  static create(r) {
    return new c((i) => {
      let e = !0;
      const s = {
        active: () => e,
        dispose() {
          e = !1;
        }
      };
      i.subscribe(s);
      try {
        r({
          next(t) {
            e && i.next(t);
          },
          error(t) {
            if (e)
              try {
                i.error(t);
              } finally {
                e = !1;
              }
            else
              throw t;
          },
          complete() {
            if (e)
              try {
                i.complete();
              } finally {
                e = !1;
              }
          },
          subscription: s
        });
      } catch (t) {
        try {
          i.error(t);
        } finally {
          s.dispose(), e = !1;
        }
      }
    });
  }
  pipe(...r) {
    return r.reduce((i, e) => e(i), this);
  }
  subscribe(r, i = o, e = a) {
    let s = !0, t;
    const n = {
      active: () => s,
      dispose() {
        s && (t && t.dispose(), s = !1);
      }
    };
    return this.subscriber({
      subscribe(l) {
        t ? l.dispose() : t = l;
      },
      next(l) {
        s && r(l);
      },
      error(l) {
        if (s)
          try {
            i(l);
          } finally {
            s = !1;
          }
        else
          throw l;
      },
      complete() {
        if (s)
          try {
            e();
          } finally {
            s = !1;
          }
      }
    }), n;
  }
}
export {
  c as Observable
};
//# sourceMappingURL=observable.mjs.map
