tee-async-iterable
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

tee_async_iterable v0.2.2

tee for AsyncIterable

You can branch the given source async iterable into N async itrables.

Usage

In deno:

import { tee } from "https://deno.land/x/tee_async_iterable@v0.2.2/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:

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

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i tee-async-iterable

      Weekly Downloads

      2

      Version

      0.2.2

      License

      MIT

      Unpacked Size

      9.43 kB

      Total Files

      10

      Last publish

      Collaborators

      • kt3k