From 1cbea878e88931db98c7e5d7985cfa02c59241ec Mon Sep 17 00:00:00 2001 From: Devin Ivy Date: Mon, 13 Apr 2026 23:46:31 -0400 Subject: [PATCH] docs: update fan-out example to use assign() and run.workers Co-Authored-By: Claude Opus 4.6 (1M context) --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2db940d..c6887b3 100644 --- a/README.md +++ b/README.md @@ -327,7 +327,7 @@ for await (const n of countUp(5)) { When you pass the same `AsyncIterable` or `StreamTask` argument to multiple tasks, each task gets its own copy of the data. Use `channel()` to share a single source across multiple workers — each item goes to exactly one consumer (work stealing). ```ts -import { workers, channel, mo } from 'moroutine'; +import { workers, channel, assign, mo } from 'moroutine'; const generate = mo(import.meta, async function* (n: number) { for (let i = 0; i < n; i++) yield i; @@ -344,12 +344,17 @@ const process = mo(import.meta, async (input: AsyncIterable): Promise { + return assign(w, process(ch)); + }); + const results = await run(fanout); // Items distributed across workers — no duplicates, no gaps } ``` +Use `assign(worker, task)` to pin a task to a specific worker. `run.workers` is a read-only array of worker handles, one per pool worker. + Without `channel()`, `AsyncIterable` and `StreamTask` arguments are auto-detected and streamed to a single consumer. `channel()` is only needed for fan-out. ### Pipelines -- 2.51.2