A pipeline is an ordered list of strategies. execute(callback) runs the callback through all of them. Build it
once and reuse it: stateful strategies (circuit breaker, limiters, cache) keep their state in the pipeline, so a
pipeline built per call never opens its breaker.
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
CircuitBreakerOptions<any>.consecutiveFailures?: number |undefined
Break after this many failures in a row (a success resets the count). Simple and good for low traffic.
When set without failureRatio, the ratio check is off and only this rule applies.
ResiliencePipelineBuilder adds Polly-style addRetry() / addTimeout() / … shortcuts on top, at the cost of
bundling every strategy. Strategies run in the order they are added: the first one added is the outermost.
Options are validated and strategy state (e.g. circuit breaker) is created on build().
ResiliencePipelineBuilder adds Polly-style addRetry() / addTimeout() / … shortcuts on top, at the cost of
bundling every strategy. Strategies run in the order they are added: the first one added is the outermost.
Options are validated and strategy state (e.g. circuit breaker) is created on build().
CircuitBreakerOptions<T>.consecutiveFailures?: number |undefined
Break after this many failures in a row (a success resets the count). Simple and good for low traffic.
When set without failureRatio, the ratio check is off and only this rule applies.
Both build the same pipeline. ResiliencePipelineBuilder has an addX() shortcut for every strategy and therefore
bundles all of them (15.1 KB). PipelineBuilder only has add(), so only the xStrategy() definitions you import
end up in your bundle. ResiliencePipelineBuilder also accepts add(xStrategy(...)), so the two mix freely.
Builder option
Default
Effect
name
none
Labels telemetry events (source.pipelineName)
timeProvider
system clock
Clock for every strategy; FakeTimeProvider in tests
unrefTimers
false
Pending timers don’t keep the process alive (CLIs, scripts). Ignored with timeProvider
tags
none
Labels added to every telemetry event of this pipeline
instrumentation
none
Hooks for this pipeline only, or false to opt out of all
telemetry
true
false emits no events from this pipeline
Options are validated, and strategy state is created, on build(). Each build() creates fresh state.
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
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:
constoutcome=await pipeline.settle(async () => (user ? user : Outcome.fromError(newNotFound(id))));
const getUser = pipeline.wrap(api.getUser): a function with the same arguments that runs through the pipeline.
wrap(
constapi: {
getUser(id:string):Promise<{
id:string;
}>;
}
api.
functiongetUser(id:string):Promise<{
id:string;
}>
getUser.
CallableFunction.bind<(id:string) =>Promise<{
id:string;
}>>(this: (id:string) =>Promise<{
id:string;
}>, thisArg:unknown): (id:string) =>Promise<{
id:string;
}> (+1 overload)
For a given function, creates a bound function that has the same body as the original function.
The this object of the bound function is associated with the specified object, and has the specified initial parameters.
@param ― thisArg The object to be used as the this object.
bind(
constapi: {
getUser(id:string):Promise<{
id:string;
}>;
}
api)); // same signature, runs through the pipeline
await
constgetUser: (id:string) =>Promise<{
id:string;
}>
getUser('42');
wrap() doesn’t pass the signal to the wrapped function. Use getResilienceSignal()
inside it, or call execute directly.
addPipeline(pipeline) inserts an existing pipeline as one strategy, with its state. Use it to share a
circuit breaker or limiter between pipelines that call the same dependency:
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
CircuitBreakerOptions<any>.consecutiveFailures?: number |undefined
Break after this many failures in a row (a success resets the count). Simple and good for low traffic.
When set without failureRatio, the ratio check is off and only this rule applies.
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
The nested pipeline’s strategies run in place; its own kill switch and dispose() are not consulted by the outer
pipeline. Dispose it yourself.
A pipeline executed inside the callback of another one is different: it runs as an independent call but inherits
the outer signal. That is deadline propagation.
Rebuild key's pipeline, optionally with a new configuration (e.g. limits from a feature flag).
Existing references keep working and pick up the new pipeline; the old one is disposed and its state dropped.
Stops background work (health checks, store sync timers). Later executions fail.
dispose(); // stops health checks and store sync timers
getStrategy() matches the strategy’s name (default 'Retry', 'CircuitBreaker', 'Timeout'…, or the
name option) or its class name. Give two strategies of the same kind distinct names.
After dispose(), execute() rejects with a plain Error and executeOutcome() returns it as a failure.