import { __commonJSMin } from "../../../../_virtual/rolldown_runtime.js";
import { require_ral } from "./ral.js";
import { require_is } from "./is.js";
import { require_events } from "./events.js";
var require_cancellation = /* @__PURE__ */ __commonJSMin(((e) => {
	Object.defineProperty(e, "__esModule", { value: !0 }), e.CancellationTokenSource = e.CancellationToken = void 0;
	var i = require_ral(), a = require_is(), o = require_events(), s;
	(function(e) {
		e.None = Object.freeze({
			isCancellationRequested: !1,
			onCancellationRequested: o.Event.None
		}), e.Cancelled = Object.freeze({
			isCancellationRequested: !0,
			onCancellationRequested: o.Event.None
		});
		function n(n) {
			let r = n;
			return r && (r === e.None || r === e.Cancelled || a.boolean(r.isCancellationRequested) && !!r.onCancellationRequested);
		}
		e.is = n;
	})(s || (e.CancellationToken = s = {}));
	var c = Object.freeze(function(e, n) {
		let r = (0, i.default)().timer.setTimeout(e.bind(n), 0);
		return { dispose() {
			r.dispose();
		} };
	}), l = class {
		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 ? c : (this._emitter ||= new o.Emitter(), this._emitter.event);
		}
		dispose() {
			this._emitter &&= (this._emitter.dispose(), void 0);
		}
	};
	e.CancellationTokenSource = class {
		get token() {
			return this._token ||= new l(), this._token;
		}
		cancel() {
			this._token ? this._token.cancel() : this._token = s.Cancelled;
		}
		dispose() {
			this._token ? this._token instanceof l && this._token.dispose() : this._token = s.None;
		}
	};
}));
export default require_cancellation();
export { require_cancellation };
