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().
Type Parameters
Section titled “Type Parameters”T = any
E = any
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ResiliencePipeline<
T,E>(strategies,options?):ResiliencePipeline<T,E>
Defined in: src/pipeline.ts:64
Parameters
Section titled “Parameters”strategies
Section titled “strategies”readonly ResilienceStrategy<T>[]
options?
Section titled “options?”PipelineOptions = {}
Returns
Section titled “Returns”ResiliencePipeline<T, E>
Properties
Section titled “Properties”
readonlyname:string|undefined
Defined in: src/pipeline.ts:57
readonlystaticempty:ResiliencePipeline<any>
Defined in: src/pipeline.ts:53
Accessors
Section titled “Accessors”disposed
Section titled “disposed”Get Signature
Section titled “Get Signature”get disposed():
boolean
Defined in: src/pipeline.ts:218
True once dispose() was called (opossum’s isShutdown).
Returns
Section titled “Returns”boolean
enabled
Section titled “enabled”Get Signature
Section titled “Get Signature”get enabled():
boolean
Defined in: src/pipeline.ts:203
Returns
Section titled “Returns”boolean
Methods
Section titled “Methods”describe()
Section titled “describe()”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.
Returns
Section titled “Returns”disable()
Section titled “disable()”disable():
void
Defined in: src/pipeline.ts:195
Kill switch: while disabled, calls bypass every strategy (no retries, no breaker, no limits).
Returns
Section titled “Returns”void
dispose()
Section titled “dispose()”dispose():
void
Defined in: src/pipeline.ts:223
Stops background work (health checks, store sync timers). Later executions fail.
Returns
Section titled “Returns”void
enable()
Section titled “enable()”enable():
void
Defined in: src/pipeline.ts:199
Returns
Section titled “Returns”void
execute()
Section titled “execute()”execute<
R>(callback,options?):Promise<R>
Defined in: src/pipeline.ts:74
Runs the callback through the pipeline; throws the final error.
Type Parameters
Section titled “Type Parameters”R
Parameters
Section titled “Parameters”callback
Section titled “callback”(context) => MaybePromise<R>
options?
Section titled “options?”Returns
Section titled “Returns”Promise<R>
executeOutcome()
Section titled “executeOutcome()”executeOutcome<
R>(callback,options?):Promise<Outcome<R>>
Defined in: src/pipeline.ts:79
Like execute, but returns the final outcome instead of throwing.
Type Parameters
Section titled “Type Parameters”R
Parameters
Section titled “Parameters”callback
Section titled “callback”(context) => MaybePromise<R>
options?
Section titled “options?”ExecuteOptions = {}
Returns
Section titled “Returns”Promise<Outcome<R>>
executeStream()
Section titled “executeStream()”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.
Type Parameters
Section titled “Type Parameters”R
Parameters
Section titled “Parameters”factory
Section titled “factory”(context) => MaybePromise<AsyncIterable<R, any, any> | ReadableStream<R>>
options?
Section titled “options?”Returns
Section titled “Returns”AsyncGenerator<R, void, undefined>
getStrategy()
Section titled “getStrategy()”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.
Type Parameters
Section titled “Type Parameters”S extends ResilienceStrategy<any> = ResilienceStrategy<any>
Parameters
Section titled “Parameters”nameOrKind
Section titled “nameOrKind”string
Returns
Section titled “Returns”S | undefined
isError()
Section titled “isError()”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.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”error is E
settle()
Section titled “settle()”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.
Type Parameters
Section titled “Type Parameters”R
E2 = never
Parameters
Section titled “Parameters”callback
Section titled “callback”(context) => MaybePromise<R | Outcome<R, E2>>
options?
Section titled “options?”Returns
Section titled “Returns”Promise<Outcome<R, UnexpectedError | E | E2>>
wrap()
Section titled “wrap()”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.
Type Parameters
Section titled “Type Parameters”A extends unknown[]
R
Parameters
Section titled “Parameters”(…args) => MaybePromise<R>
options?
Section titled “options?”Returns
Section titled “Returns”(…args) => Promise<R>