import { __exports as t } from "../../../../../../../_virtual/cancellation2.js";
import { __require as f } from "./ral.js";
import { __require as h } from "./is.js";
import { __require as C } from "./events.js";
var l;
function v() {
  if (l) return t;
  l = 1, Object.defineProperty(t, "__esModule", { value: !0 }), t.CancellationTokenSource = t.CancellationToken = void 0;
  const c = f(), u = h(), s = C();
  var i;
  (function(e) {
    e.None = Object.freeze({
      isCancellationRequested: !1,
      onCancellationRequested: s.Event.None
    }), e.Cancelled = Object.freeze({
      isCancellationRequested: !0,
      onCancellationRequested: s.Event.None
    });
    function o(r) {
      const n = r;
      return n && (n === e.None || n === e.Cancelled || u.boolean(n.isCancellationRequested) && !!n.onCancellationRequested);
    }
    e.is = o;
  })(i || (t.CancellationToken = i = {}));
  const _ = Object.freeze(function(e, o) {
    const r = (0, c.default)().timer.setTimeout(e.bind(o), 0);
    return { dispose() {
      r.dispose();
    } };
  });
  class a {
    constructor() {
      this._isCancelled = !1;
    }
    cancel() {
      this._isCancelled || (this._isCancelled = !0, this._emitter && (this._emitter.fire(void 0), this.dispose()));
    }
    get isCancellationRequested() {
      return this._isCancelled;
    }
    get onCancellationRequested() {
      return this._isCancelled ? _ : (this._emitter || (this._emitter = new s.Emitter()), this._emitter.event);
    }
    dispose() {
      this._emitter && (this._emitter.dispose(), this._emitter = void 0);
    }
  }
  class d {
    get token() {
      return this._token || (this._token = new a()), this._token;
    }
    cancel() {
      this._token ? this._token.cancel() : this._token = i.Cancelled;
    }
    dispose() {
      this._token ? this._token instanceof a && this._token.dispose() : this._token = i.None;
    }
  }
  return t.CancellationTokenSource = d, t;
}
export {
  v as __require
};
