Skip to content

ResiliencePipelineBuilder

Defined in: src/builder.ts:44

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().

T = any

E = never

C extends string = never

new ResiliencePipelineBuilder<T, E, C>(options?): ResiliencePipelineBuilder<T, E, C>

Defined in: src/pipeline-builder.ts:62

ResiliencePipelineBuilderOptions = {}

ResiliencePipelineBuilder<T, E, C>

PipelineBuilder.constructor

readonly name: string | undefined

Defined in: src/pipeline-builder.ts:56

PipelineBuilder.name


readonly tags: Readonly<Record<string, string>> | undefined

Defined in: src/pipeline-builder.ts:58

PipelineBuilder.tags


readonly timeProvider: TimeProvider

Defined in: src/pipeline-builder.ts:57

PipelineBuilder.timeProvider

add<D>(definition): ResiliencePipelineBuilder<T, WithErrors<E, C, ErrorsOf<D>>, C | CatchesOf<D>>

Defined in: src/builder.ts:45

D extends StrategyDefinition<T, any>

D

ResiliencePipelineBuilder<T, WithErrors<E, C, ErrorsOf<D>>, C | CatchesOf<D>>

PipelineBuilder.add


addAdaptiveConcurrencyLimiter(options?): Next<T, E, C, BulkheadRejectedError>

Defined in: src/builder.ts:108

Concurrency limit that tunes itself from observed latency and failures (gradient2 / vegas / aimd), so you don’t have to guess the right number: it grows while the dependency keeps up and backs off when it queues.

AdaptiveConcurrencyLimiterOptions<T> = {}

Next<T, E, C, BulkheadRejectedError>


addCache(options): this

Defined in: src/builder.ts:128

Cache successful results by key, coalesce concurrent identical calls, optionally serve stale values on failure.

CacheOptions<T>

this


addChaosBehavior(options): this

Defined in: src/builder.ts:154

ChaosBehaviorOptions

this


addChaosFault(options): this

Defined in: src/builder.ts:142

ChaosFaultOptions

this


addChaosLatency(options): this

Defined in: src/builder.ts:150

ChaosLatencyOptions

this


addChaosOutcome(options): this

Defined in: src/builder.ts:146

ChaosOutcomeOptions<T>

this


addCircuitBreaker(options?): Next<T, E, C, BrokenCircuitError>

Defined in: src/builder.ts:64

CircuitBreakerOptions<T> = {}

Next<T, E, C, BrokenCircuitError>


addCoalesce(options?): this

Defined in: src/builder.ts:133

Single-flight only: concurrent executions with the same key share one call; nothing is cached.

Omit<CacheOptions<T>, "ttl" | "staleTtl" | "store" | "shouldCache"> = {}

this


addConcurrencyLimiter(options, queueLimit?): Next<T, E, C, BulkheadRejectedError>

Defined in: src/builder.ts:95

addConcurrencyLimiter(10), addConcurrencyLimiter(10, 50) or full options.

number | ConcurrencyLimiterOptions

number = 0

Next<T, E, C, BulkheadRejectedError>


addFallback(options): ResiliencePipelineBuilder<T, E, string>

Defined in: src/builder.ts:69

Without shouldHandle it catches every failure of the strategies added after it, so their errors leave the error type.

FallbackOptions<T> & object

ResiliencePipelineBuilder<T, E, string>

addFallback(options): this

Defined in: src/builder.ts:70

Without shouldHandle it catches every failure of the strategies added after it, so their errors leave the error type.

FallbackOptions<T>

this


addFallbackOn<K>(codes, fallbackAction, options?): ResiliencePipelineBuilder<T, E, C | K>

Defined in: src/builder.ts:76

Fallback for these error codes only; they leave the settle() error type of the strategies added after it.

K extends string

readonly K[]

(args) => MaybePromise<T>

Omit<FallbackOptions<T>, "shouldHandle" | "fallbackAction">

ResiliencePipelineBuilder<T, E, C | K>


addFixedWindowRateLimiter(options): Next<T, E, C, RateLimiterRejectedError>

Defined in: src/builder.ts:113

Fixed-window rate limit: permitLimit per window. Optional permits(ctx) weight and queueTimeout.

FixedWindowRateLimiterOptions

Next<T, E, C, RateLimiterRejectedError>


addHedging(options?): this

Defined in: src/builder.ts:90

HedgingOptions<T> = {}

this


addLock(options): Next<T, E, C, LockNotAcquiredError | LockLostError>

Defined in: src/builder.ts:138

Run under a (distributed, with a custom store) lock: leases, renewal, fencing tokens.

LockOptions

Next<T, E, C, LockNotAcquiredError | LockLostError>


addMapError<E2>(mapper): ResiliencePipelineBuilder<T, E | E2, string>

Defined in: src/builder.ts:81

Turns every failure of the strategies added after it into your own error type (theirs leave the error type).

E2

(error, context) => E2

ResiliencePipelineBuilder<T, E | E2, string>


addPartitionedRateLimiter(options): Next<T, E, C, RateLimiterRejectedError>

Defined in: src/builder.ts:123

One limiter per key (user, tenant, API key…), created on demand and evicted when idle.

PartitionedRateLimiterOptions<T>

Next<T, E, C, RateLimiterRejectedError>


addPipeline<E2>(pipeline): Next<T, E, C, E2>

Defined in: src/builder.ts:50

Nest an existing pipeline (and its state) as a single strategy.

E2

ResiliencePipeline<T, E2>

Next<T, E, C, E2>

PipelineBuilder.addPipeline


addRateLimiter(options): Next<T, E, C, RateLimiterRejectedError>

Defined in: src/builder.ts:100

Token bucket rate limiter.

TokenBucketOptions

Next<T, E, C, RateLimiterRejectedError>


addRetry(options?): this

Defined in: src/builder.ts:55

RetryOptions<T> = {}

this


addSlidingWindowRateLimiter(options): Next<T, E, C, RateLimiterRejectedError>

Defined in: src/builder.ts:118

Sliding-window rate limit: smooths the burst a fixed window allows at its edges.

SlidingWindowRateLimiterOptions

Next<T, E, C, RateLimiterRejectedError>


addStaleFallback(options): this

Defined in: src/builder.ts:86

Serve the last good value when a call fails (no caching of fresh calls): tenace’s withStaleFallback.

StaleFallbackOptions<T>

this


addStrategy(create, name?): this

Defined in: src/pipeline-builder.ts:75

Plug in your own strategy.

StrategyFactory<T>

string

this

PipelineBuilder.addStrategy


addTimeout(options): Next<T, E, C, TimeoutRejectedError>

Defined in: src/builder.ts:60

addTimeout(5000), addTimeout('5s') or addTimeout({ timeout: '5s', onTimeout }).

Duration | TimeoutOptions

Next<T, E, C, TimeoutRejectedError>


build(): ResiliencePipeline<T, E>

Defined in: src/builder.ts:158

ResiliencePipeline<T, E>

PipelineBuilder.build