Skip to main content

@std/async@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)
function tee
tee<T, N extends number = 2>(
iterable: AsyncIterable<T>,
n?: N
): Tuple<AsyncIterable<T>, N>

Branches the given async iterable into the n branches.

Examples

Example 1

import { tee } from "@std/async/tee";

const gen = async function* gen() {
  yield 1;
  yield 2;
  yield 3;
};

const [branch1, branch2] = tee(gen());

for await (const n of branch1) {
  console.log(n); // => 1, 2, 3
}

for await (const n of branch2) {
  console.log(n); // => 1, 2, 3
}

Type Parameters

Parameters

iterable: AsyncIterable<T>
optional
n: N

Return Type

Tuple<AsyncIterable<T>, N>

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/async

Import symbol

import { tee } from "@std/async/tee";
or

Import directly with a jsr specifier

import { tee } from "jsr:@std/async/tee";