@orkestrel/agent 0.0.16 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1102,6 +1102,18 @@ export declare interface AuthorityRule {
1102
1102
  * `push` / `close` / `fail` enqueue/flag, then fire `#wake` so the parked reader wakes,
1103
1103
  * re-reads the buffer, and either yields the next chunk, returns (on `close`), or throws
1104
1104
  * (on `fail`). Event-free, no `!` / `as` / `any`.
1105
+ *
1106
+ * @example
1107
+ * ```ts
1108
+ * import { Channel } from '@orkestrel/agent'
1109
+ *
1110
+ * const channel = new Channel<number>()
1111
+ * channel.push(1)
1112
+ * channel.close()
1113
+ * for await (const value of channel.drain()) {
1114
+ * value // 1
1115
+ * }
1116
+ * ```
1105
1117
  */
1106
1118
  export declare class Channel<T> {
1107
1119
  #private;
@@ -1287,6 +1287,18 @@ var AgentContext = class {
1287
1287
  * `push` / `close` / `fail` enqueue/flag, then fire `#wake` so the parked reader wakes,
1288
1288
  * re-reads the buffer, and either yields the next chunk, returns (on `close`), or throws
1289
1289
  * (on `fail`). Event-free, no `!` / `as` / `any`.
1290
+ *
1291
+ * @example
1292
+ * ```ts
1293
+ * import { Channel } from '@orkestrel/agent'
1294
+ *
1295
+ * const channel = new Channel<number>()
1296
+ * channel.push(1)
1297
+ * channel.close()
1298
+ * for await (const value of channel.drain()) {
1299
+ * value // 1
1300
+ * }
1301
+ * ```
1290
1302
  */
1291
1303
  var Channel = class {
1292
1304
  #buffer = [];
@@ -1294,7 +1306,7 @@ var Channel = class {
1294
1306
  #closed = false;
1295
1307
  #failure;
1296
1308
  push(value) {
1297
- this.#buffer.push(value);
1309
+ this.#buffer.push({ value });
1298
1310
  this.#signal();
1299
1311
  }
1300
1312
  close() {
@@ -1308,10 +1320,7 @@ var Channel = class {
1308
1320
  }
1309
1321
  async *drain() {
1310
1322
  for (;;) {
1311
- while (this.#buffer.length > 0) {
1312
- const next = this.#buffer.shift();
1313
- if (next !== void 0) yield next;
1314
- }
1323
+ for (let cell = this.#buffer.shift(); cell !== void 0; cell = this.#buffer.shift()) yield cell.value;
1315
1324
  if (this.#failure !== void 0) throw this.#failure.error;
1316
1325
  if (this.#closed) return;
1317
1326
  await this.#parked();