Stream.splitN(n: 0 | 1,bufferSize: number,options?: SplitOptions): [Stream<T, E | PumpError>]
Splits the stream into n separate streams that each receive the same results.
If one of the split streams is slower than the others, it will cause backpressure on the source stream and all other splits until it catches up. Use with caution to avoid unintended bottlenecks.
Example 1
Example 1
import { Source } from "anabranch"; const stream = Source.from<number, never>(async function* () { yield 1; yield 2; yield 3; }); const [streamA, streamB] = stream.splitN(2, 10); for await (const value of streamA) { console.log("Stream A:", value); } for await (const value of streamB) { console.log("Stream B:", value); }
[Stream<T, E | PumpError>]
Stream.splitN(n: 2,bufferSize: number,options?: SplitOptions): [Stream<T, E | PumpError>, Stream<T, E | PumpError>]