Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kt3k/tee_async_iterable
tee for AsyncIterable
https://github.com/kt3k/tee_async_iterable
Last synced: 20 days ago
JSON representation
tee for AsyncIterable
- Host: GitHub
- URL: https://github.com/kt3k/tee_async_iterable
- Owner: kt3k
- License: mit
- Created: 2021-04-25T05:46:03.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-13T06:10:46.000Z (almost 3 years ago)
- Last Synced: 2024-10-17T04:44:44.015Z (27 days ago)
- Language: TypeScript
- Size: 12.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tee_async_iterable v0.2.3
> [tee](https://en.wikipedia.org/wiki/Tee_%28command%29) for AsyncIterable
You can branch the given source async iterable into N async itrables.
# Usage
In deno:
```ts
import { tee } from "https://deno.land/x/[email protected]/tee.ts";// The source async iterator
const gen = async function* gen() {
yield 1;
yield 2;
yield 3;
};// Branches the source iterator into 2 iterators.
const [branch1, branch2] = tee(gen());// 2 iterators work independently.
(async () => {
for await (const n of branch1) {
console.log(n); // => 1, 2, 3
}
})();(async () => {
for await (const n of branch2) {
console.log(n); // => 1, 2, 3
}
})();
```In node.js:
```ts
import { tee } from "tee-async-iterable";// The source async iterator
const gen = async function* gen() {
yield 1;
yield 2;
yield 3;
};// Branches the source iterator into 2 iterators.
const [branch1, branch2] = tee(gen());// 2 iterators work independently.
(async () => {
for await (const n of branch1) {
console.log(n); // => 1, 2, 3
}
})();(async () => {
for await (const n of branch2) {
console.log(n); // => 1, 2, 3
}
})();
```# License
MIT