diff options
| author | Yuval Adam <_@yuv.al> | 2025-03-21 22:16:47 +0100 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2025-03-21 22:16:47 +0100 |
| commit | 9b56aaa7a1aefc2fd07e3bf4baedf9206d9dd7ad (patch) | |
| tree | fd7de4f4d4647d160b2b3e22d8e7f94f1d032471 /example.py | |
| parent | d8846814f319fb792fbb1d7f48c41f911fce609c (diff) | |
Solidify Batch API
Diffstat (limited to 'example.py')
| -rw-r--r-- | example.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/example.py b/example.py new file mode 100644 index 0000000..08fd8b0 --- /dev/null +++ b/example.py @@ -0,0 +1,43 @@ +import asyncio + +from rivulet import Pipeline, Batch + + +async def source(): + for i in range(22): + yield i + + +async def double(gen): + async for value in gen: + yield value * 2 + + +async def dump(gen): + async for x in gen: + print(x) + yield x + + +async def sum(batches): + async for batch in batches: + res = 0 + for x in batch: + res += x + yield res + + +async def main(): + pipe = Pipeline(source()) + pipe.add_step(double) + + batch = Batch(N=5, timeout=0.1) + pipe.add_step(batch) + pipe.add_step(dump) + pipe.add_step(sum) + + res = await pipe.collect() + print(res) + + +asyncio.run(main()) |
