//#region src/client/stream/multi-cursor-buffer.ts
/**
* Multi-cursor buffer that supports independent async iterators over a
* shared append-only log of items.  Each `for await` loop gets its own
* cursor starting at position 0, so late consumers still see all
* previously buffered items.
*
* Mirrors the in-process multi-cursor buffering used by `GraphRunStream`.
*/
var MultiCursorBuffer = class {
	#items = [];
	#wakeups = /* @__PURE__ */ new Set();
	#closed = false;
	push(item) {
		this.#items.push(item);
		for (const cb of this.#wakeups) cb();
		this.#wakeups.clear();
	}
	close() {
		this.#closed = true;
		for (const cb of this.#wakeups) cb();
		this.#wakeups.clear();
	}
	get length() {
		return this.#items.length;
	}
	[Symbol.asyncIterator]() {
		let cursor = 0;
		return {
			next: async () => {
				while (true) {
					if (cursor < this.#items.length) return {
						done: false,
						value: this.#items[cursor++]
					};
					if (this.#closed) return {
						done: true,
						value: void 0
					};
					await new Promise((resolve) => {
						this.#wakeups.add(resolve);
					});
				}
			},
			return: async () => ({
				done: true,
				value: void 0
			})
		};
	}
};
//#endregion
export { MultiCursorBuffer };

//# sourceMappingURL=multi-cursor-buffer.js.map