polly_dart 0.0.9
polly_dart: ^0.0.9 copied to clipboard
A Dart port of Polly (.NET resilience library) providing strategies like Retry, Circuit Breaker, Timeout, Rate Limiter, Hedging, and Fallback.
0.0.9 #
No breaking changes. All existing APIs are preserved.
Circuit Breaker #
OnCircuitOpenedArgumentsgains two optional fields:Outcome<T>? outcome(the failing outcome that triggered the open) andbool isManual(whether the circuit was opened viaCircuitBreakerManualControl.isolateAsync). Both default to their zero values so existing callbacks continue to compile unchanged.OnCircuitClosedArgumentsgainsbool isManual(whether the circuit was closed viaCircuitBreakerManualControl.closeAsync), defaulting tofalse.BreakDurationGeneratorArgumentsgainsOutcome<T>? outcomeso custom break-duration logic can inspect the specific error that caused the circuit to open (e.g. apply a longer break for a 503 than a 500).
Rate Limiter #
RateLimiterRejectedExceptiongainsDuration? retryAfter— the suggested wait time before retrying. Populated for token-bucket, fixed-window, and sliding-window limiters;nullfor concurrency limiters where the release time is unknown.OnRateLimiterRejectedArgumentsgains the sameDuration? retryAfterfield so rejection callbacks receive the hint without catching the exception.
Hedging #
OnHedgingArgumentsgainsOutcome<T>? outcome— the primary outcome if the primary attempt already completed with a handled result before the hedge was triggered;nullwhen the hedge fires speculatively while the primary is still in-flight.HedgingDelayGeneratorArgumentsgainsOutcome<T>? primaryOutcomewith the same semantics.
Outcome #
tryGetResult()— returns the result if successful, ornullif the outcome represents an exception. Avoids a try/catch when you just want an optional value.tryGetException()— returns the exception if present, ornullif the outcome represents a successful result.when<R>({required onResult, required onException})— exhaustive match helper that calls the appropriate handler and returns its value, eliminating repeatedhasResultchecks.
PredicateBuilder #
handleWhen<TException>(bool Function(TException) predicate)— adds a predicate that handles exceptions of a specific type only when an additional condition on the exception instance is true (e.g.handleWhen<HttpException>((e) => e.statusCode >= 500)).
ResiliencePipeline #
ResiliencePipeline.empty— a pre-built, reusable no-op pipeline that executes callbacks directly without any resilience wrapping. Useful as a default value in optional-pipeline patterns and dependency injection scenarios.
Retry #
- Fixed jitter implementation to match .NET Polly's decorrelated-jitter formula:
delay × (1 + random ∈ [−0.5, 0.5)), giving a final delay in the range [50 %, 150 %] of the calculated base. Previously the jitter replaced the entire delay with a random value in[0, base), which could collapse the delay to near-zero.
0.0.8 #
No breaking changes. All existing APIs are preserved.
New #
CancellationToken— new public class that bridges the pipeline's cancellation signal to external resources (HTTP clients, etc.). ExposesisCancelled,whenCancelled(Future<void>),cancel(), andthrowIfCancelled().ResilienceContext.cancellationToken— getter that returns the context'sCancellationToken, ready to pass into HTTP client adapters.ResilienceContext.copy()now propagates parent cancellation to child contexts automatically (previously child contexts were independent after copying).
Internal #
OperationCancelledExceptionmoved fromresilience_context.dartto the newcancellation_token.dart. It is still re-exported by both files, so any existingimport 'package:polly_dart/polly_dart.dart'continues to resolve it unchanged.- Repo converted to a melos monorepo. Extension packages (
polly_dart_http,polly_dart_dio) live inextensions/and are published as separate packages.
0.0.7 #
- Update README with examples of cache strategy usage
0.0.6 #
- Add cache strategy support
- Fix version in the readme installation example
0.0.5 #
- ReFormat the changelog for consistency
0.0.4 #
- Reorganize the changelog
0.0.3 #
- Update pub homepage link to point to the correct documentation website
0.0.2 #
- Add docs
0.0.1 #
- Initial version.