Skip to content
Buy me a coffee

ResiliencePipeline

Defined in: src/pipeline.ts:52

T: what callbacks may return. E (type-only): the errors the pipeline’s strategies can raise, for settle().

T = any

E = any

new ResiliencePipeline<T, E>(strategies, options?): ResiliencePipeline<T, E>

Defined in: src/pipeline.ts:64

readonly ResilienceStrategy<T>[]

PipelineOptions = {}

ResiliencePipeline<T, E>

readonly name: string | undefined

Defined in: src/pipeline.ts:57


readonly static empty: ResiliencePipeline<any>

Defined in: src/pipeline.ts:53

get disposed(): boolean

Defined in: src/pipeline.ts:218

True once dispose() was called (opossum’s isShutdown).

boolean


get enabled(): boolean

Defined in: src/pipeline.ts:203

boolean

describe(): StrategyDescriptor[]

Defined in: src/pipeline.ts:208

The strategies in execution order (outermost first), e.g. to assert a pipeline’s configuration in tests.

StrategyDescriptor[]


disable(): void

Defined in: src/pipeline.ts:195

Kill switch: while disabled, calls bypass every strategy (no retries, no breaker, no limits).

void


dispose(): void

Defined in: src/pipeline.ts:223

Stops background work (health checks, store sync timers). Later executions fail.

void


enable(): void

Defined in: src/pipeline.ts:199

void


execute<R>(callback, options?): Promise<R>

Defined in: src/pipeline.ts:74

Runs the callback through the pipeline; throws the final error.

R

(context) => MaybePromise<R>

ExecuteOptions

Promise<R>


executeOutcome<R>(callback, options?): Promise<Outcome<R>>

Defined in: src/pipeline.ts:79

Like execute, but returns the final outcome instead of throwing.

R

(context) => MaybePromise<R>

ExecuteOptions = {}

Promise<Outcome<R>>


executeStream<R>(factory, options?): AsyncGenerator<R, void, undefined>

Defined in: src/pipeline.ts:158

Runs a streaming call (an AsyncIterable or a ReadableStream) through the pipeline. Everything up to the first chunk is protected: retries, timeouts (time to first chunk), breaker, limiters. Once the first chunk arrives the stream is committed: later errors reach the consumer and are not retried or replaced by a fallback, which would repeat data already delivered. Breaking out of the loop closes the underlying stream.

R

(context) => MaybePromise<AsyncIterable<R, any, any> | ReadableStream<R>>

ExecuteOptions

AsyncGenerator<R, void, undefined>


getStrategy<S>(nameOrKind): S | undefined

Defined in: src/pipeline.ts:213

The strategy instance named name (or of class kind), to read its live state: getStrategy<CircuitBreakerStrategy>('CircuitBreaker')?.state.

S extends ResilienceStrategy<any> = ResilienceStrategy<any>

string

S | undefined


isError(error): error is E

Defined in: src/pipeline.ts:148

Is this one of the errors this pipeline can produce (E)? Resilience errors and mapError results.

unknown

error is E


settle<R, E2>(callback, options?): Promise<Outcome<R, UnexpectedError | E | E2>>

Defined in: src/pipeline.ts:133

Like executeOutcome, but the error is typed: the errors this pipeline’s strategies can raise (E), the errors your callback returns with Outcome.fromError(…) (E2), or UnexpectedError wrapping anything else (a thrown bug, a client error). Pair it with Outcome.match() for exhaustive handling:

const outcome = await pipeline.settle(async () => (user ? user : Outcome.fromError(new NotFound(id))));
Outcome.match(outcome, { ok: (u) => u, NOT_FOUND: () => null, TIMEOUT: () => cached, CIRCUIT_OPEN: () => cached, UNEXPECTED: (e) => { throw e } });

Returned errors count as failures for the strategies (they can be retried) unless your predicates say otherwise.

R

E2 = never

(context) => MaybePromise<R | Outcome<R, E2>>

ExecuteOptions

Promise<Outcome<R, UnexpectedError | E | E2>>


wrap<A, R>(fn, options?): (…args) => Promise<R>

Defined in: src/pipeline.ts:190

const getUser = pipeline.wrap(api.getUser): a function with the same arguments that runs through the pipeline.

A extends unknown[]

R

(…args) => MaybePromise<R>

ExecuteOptions

(…args) => Promise<R>