@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.
- package/dist/src/core/index.cjs +14 -5
- package/dist/src/core/index.cjs.map +1 -0
- package/dist/src/core/index.d.cts +12 -0
- package/dist/src/core/index.d.ts +12 -0
- package/dist/src/core/index.js +14 -5
- package/dist/src/core/index.js.map +1 -0
- package/package.json +18 -15
package/dist/src/core/index.cjs
CHANGED
|
@@ -1288,6 +1288,18 @@ var AgentContext = class {
|
|
|
1288
1288
|
* `push` / `close` / `fail` enqueue/flag, then fire `#wake` so the parked reader wakes,
|
|
1289
1289
|
* re-reads the buffer, and either yields the next chunk, returns (on `close`), or throws
|
|
1290
1290
|
* (on `fail`). Event-free, no `!` / `as` / `any`.
|
|
1291
|
+
*
|
|
1292
|
+
* @example
|
|
1293
|
+
* ```ts
|
|
1294
|
+
* import { Channel } from '@orkestrel/agent'
|
|
1295
|
+
*
|
|
1296
|
+
* const channel = new Channel<number>()
|
|
1297
|
+
* channel.push(1)
|
|
1298
|
+
* channel.close()
|
|
1299
|
+
* for await (const value of channel.drain()) {
|
|
1300
|
+
* value // 1
|
|
1301
|
+
* }
|
|
1302
|
+
* ```
|
|
1291
1303
|
*/
|
|
1292
1304
|
var Channel = class {
|
|
1293
1305
|
#buffer = [];
|
|
@@ -1295,7 +1307,7 @@ var Channel = class {
|
|
|
1295
1307
|
#closed = false;
|
|
1296
1308
|
#failure;
|
|
1297
1309
|
push(value) {
|
|
1298
|
-
this.#buffer.push(value);
|
|
1310
|
+
this.#buffer.push({ value });
|
|
1299
1311
|
this.#signal();
|
|
1300
1312
|
}
|
|
1301
1313
|
close() {
|
|
@@ -1309,10 +1321,7 @@ var Channel = class {
|
|
|
1309
1321
|
}
|
|
1310
1322
|
async *drain() {
|
|
1311
1323
|
for (;;) {
|
|
1312
|
-
|
|
1313
|
-
const next = this.#buffer.shift();
|
|
1314
|
-
if (next !== void 0) yield next;
|
|
1315
|
-
}
|
|
1324
|
+
for (let cell = this.#buffer.shift(); cell !== void 0; cell = this.#buffer.shift()) yield cell.value;
|
|
1316
1325
|
if (this.#failure !== void 0) throw this.#failure.error;
|
|
1317
1326
|
if (this.#closed) return;
|
|
1318
1327
|
await this.#parked();
|