API · Consume

toArray()

Start the stream, collect successful values, and invoke a callback once at completion.

Signature

toArray(fn: (values: T[], context: AggregateContext<T[], C>) => void): void

Example

exstream(rows).toArray((values) => {
  console.log(`received ${values.length} rows`)
})

Parameters

fn

Type (values, context) => voidRequired

Called once with the complete array. Context is supplied only when the callback declares a second parameter.

Completion and memory

This is a terminal callback API: it resumes the pipeline immediately, returns undefined, and retains every successful value until end. It is unsuitable for infinite or memory-unbounded input. The callback receives an aggregate context when contexts were materialized.

Errors

Record errors are emitted as 'error' events on the end of the chain and are not included in the array. Without an error listener this can become an uncaught runtime error. toArray() offers no rejection channel; prefer toPromise() for structured async error handling.

Forms

stream.toArray(callback)
exstream.toArray(callback, stream)
exstream.toArray(callback)(stream)

toPromise(), collect(), values()