Who this is for: projects using cockatiel’s policies (retry, circuitBreaker, timeout, bulkhead, fallback, wrap) that want hedging, rate limiting, caching, typed errors, shared state across instances, or framework integrations.
Both libraries descend from Polly, so the concepts map one to one. The main change is shape: cockatiel builds separate policies and wrap()s them; here you add strategies to one builder. The order rule is the same: the first one is the outermost.
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.
delay: 128, maxDelay: '30s' with useJitter: true reproduces ExponentialBackoff’s defaults (decorrelated jitter, 128 ms first delay, 30 s cap). For the smallest browser bundle, use PipelineBuilder with retryStrategy(), circuitBreakerStrategy() and timeoutStrategy() instead.
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().
ResiliencePipelineBuilder<
interfaceResponse
The Response interface of the Fetch API represents the response to a request.
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().
Time-based window: calls of the last samplingDuration. Default 30 s. Ignored when samplingCount is set.
samplingDuration: '30s',
CircuitBreakerOptions<any>.minimumRps?: number |undefined
Time window only: also require this many calls per second (averaged over samplingDuration) before the ratio counts,
so a quiet period's few failures can't open the circuit (cockatiel's SamplingBreaker minimumRps).
minimumRps: 5,
CircuitBreakerOptions<any>.minimumThroughput?: number |undefined
Minimum recorded calls in the window before the ratio is considered. Default 100.
minimumThroughput: 1, // the ratio rule's own floor; minimumRps already guards quiet periods
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().
constsignal=getResilienceSignal(); // the context isn't appended to the arguments
/* … */
}
}
@resilient works with both standard (TC39) and experimentalDecorators. @usePolicy appends the context as the last argument; @resilient leaves your arguments alone and exposes the context through getResilienceContext() / getResilienceSignal().
handleAll vs our default. Without shouldHandle, retry and the breaker skip 4xx client errors (except 408/429), rejections from other strategies and caller aborts. Even with shouldHandle: ({ outcome }) => !outcome.ok, an open circuit is never retried, and the breaker never counts rejections.
A breaker needs no explicit algorithm.addCircuitBreaker() alone uses Polly’s defaults: 10% failures over at least 100 calls in 30 s, 5 s break. Port your halfOpenAfter to breakDuration and your breaker to the matching options.
Unhandled errors are ignored by the breaker: they don’t count as failures or successes.
Half-open probes are bounded. A probe that hangs longer than halfOpenMaxWait (30 s) counts as failed, so the circuit can’t stay half-open forever. halfOpenMaxCalls lets several probes through.
Attempt numbers.context.attemptNumber is 0 on the first call, like cockatiel’s context.attempt. In onRetry, cockatiel’s attempt is the upcoming retry (starting at 1); our attemptNumber is the attempt that just failed (starting at 0), so ours is one lower.
Timeout errors. An aggressive cockatiel timeout throws TaskCancelledError; ours throws TimeoutRejectedError. Both abort the signal.
Events. cockatiel’s events return disposables; our callbacks are options, and onTelemetry() returns an unsubscribe function.
Bundle size. cockatiel is smaller: 3.7 KB against our 7.1 KB for retry + breaker + timeout (min+gzip). See Bundle sizes.