
//#region src/utils/external_progress_channel.ts
/**
* Multi-producer single-consumer unit-signal channel used to wake the
* {@link PromisesExecutor} when any external progress source (input read or
* run-closure completion) has made progress.
*
* Producers call {@link signal} to emit a progress event.
* The single consumer calls {@link awaitNext} to await the next signal.
*
* Signals emitted with no consumer waiting are buffered, so no progress signal
* is ever lost. At most one {@link awaitNext} may be pending at a time; a
* concurrent second call rejects.
*/
var ExternalProgressChannel = class {
	pending = 0;
	waiter;
	signal() {
		if (this.waiter !== void 0) {
			const w = this.waiter;
			this.waiter = void 0;
			w();
		} else this.pending++;
	}
	awaitNext() {
		if (this.waiter !== void 0) return Promise.reject(/* @__PURE__ */ new Error("awaitNext already pending"));
		if (this.pending > 0) {
			this.pending--;
			return Promise.resolve();
		}
		return new Promise((resolve) => {
			this.waiter = resolve;
		});
	}
};

//#endregion
exports.ExternalProgressChannel = ExternalProgressChannel;