Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / finalize

Function: finalize()

finalize<T>(callback): Operator<T, T>

Defined in: projects/libraries/streamix/src/lib/operators/finalize.ts:16

Creates a stream operator that invokes a finalizer callback upon stream termination.

This operator is useful for performing cleanup tasks, such as closing resources or logging, after a stream has completed or encountered an error. The provided callback is guaranteed to be called exactly once, regardless of whether the stream terminates gracefully or with an error.

Type Parameters

T

T = any

The type of the values emitted by the stream.

Parameters

callback

() => MaybePromise<T>

The function to be called when the stream completes or errors. It can be synchronous or return a Promise.

Returns

Operator<T, T>

An Operator instance that can be used in a stream's pipe method.

Released under the MIT License.