Package: effect
Module: Stream
Allows a faster producer to progress independently of a slower consumer by
buffering up to capacity chunks in a queue.
Details
Finite buffers use the configured queue strategy: "suspend" applies
backpressure, while "dropping" and "sliding" may discard chunks when the
buffer is full. This combinator preserves chunking and is best with
power-of-2 capacities.
Example (Buffering stream chunks)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const result = yield* Stream.fromArrays([1, 2], [3, 4]).pipe(
Stream.bufferArray({ capacity: 2 }),
Stream.runCollect
)
yield* Console.log(result)
})
// Output: [ 1, 2, 3, 4 ]
Signature
declare const bufferArray: { (options: { readonly capacity: "unbounded"; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; }): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, R>; <A, E, R>(self: Stream<A, E, R>, options: { readonly capacity: "unbounded"; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; }): Stream<A, E, R>; }
Since v4.0.0