import { __commonJSMin } from "../../../../_virtual/rolldown_runtime.js";
import { require_cancellation } from "./cancellation.js";
var require_sharedArrayCancellation = /* @__PURE__ */ __commonJSMin(((e) => {
	Object.defineProperty(e, "__esModule", { value: !0 }), e.SharedArrayReceiverStrategy = e.SharedArraySenderStrategy = void 0;
	var n = require_cancellation(), r;
	(function(e) {
		e.Continue = 0, e.Cancelled = 1;
	})(r ||= {}), e.SharedArraySenderStrategy = class {
		constructor() {
			this.buffers = /* @__PURE__ */ new Map();
		}
		enableCancellation(e) {
			if (e.id === null) return;
			let t = new SharedArrayBuffer(4), n = new Int32Array(t, 0, 1);
			n[0] = r.Continue, this.buffers.set(e.id, t), e.$cancellationData = t;
		}
		async sendCancellation(e, t) {
			let n = this.buffers.get(t);
			if (n === void 0) return;
			let i = new Int32Array(n, 0, 1);
			Atomics.store(i, 0, r.Cancelled);
		}
		cleanup(e) {
			this.buffers.delete(e);
		}
		dispose() {
			this.buffers.clear();
		}
	};
	var i = class {
		constructor(e) {
			this.data = new Int32Array(e, 0, 1);
		}
		get isCancellationRequested() {
			return Atomics.load(this.data, 0) === r.Cancelled;
		}
		get onCancellationRequested() {
			throw Error("Cancellation over SharedArrayBuffer doesn't support cancellation events");
		}
	}, a = class {
		constructor(e) {
			this.token = new i(e);
		}
		cancel() {}
		dispose() {}
	};
	e.SharedArrayReceiverStrategy = class {
		constructor() {
			this.kind = "request";
		}
		createCancellationTokenSource(e) {
			let t = e.$cancellationData;
			return t === void 0 ? new n.CancellationTokenSource() : new a(t);
		}
	};
}));
export default require_sharedArrayCancellation();
export { require_sharedArrayCancellation };
