Expand description
execution-policy — closure-first reliability policies for any async operation.
Wrap any async operation with retry, backoff, jitter, and per-attempt / total
timeouts (circuit breaking, bounded concurrency, and retry budgets build on
this foundation). The operation is a factory — re-invoked per attempt — so
requests are freshly constructed and never need Clone, and !Send
operations are accepted.
use std::time::Duration;
use execution_policy::{ExecutionPolicyBuilder, Retry};
let policy = ExecutionPolicyBuilder::<u32, &str>::new()
.retry(Retry::exponential().max_attempts(3))
.attempt_timeout(Duration::from_secs(2))
.build();
let value = policy.run(async || Ok::<_, &str>(7u32)).await.unwrap();
assert_eq!(value, 7);Re-exports§
pub use crate::attempt::Attempt;pub use crate::breaker::CircuitBreaker;pub use crate::builder::BuildError;pub use crate::builder::ExecutionPolicyBuilder;pub use crate::classify::FailureClass;pub use crate::classify::RetryDecision;pub use crate::concurrency::ConcurrencyLimit;pub use crate::concurrency::SaturationPolicy;pub use crate::core::DefaultCore;pub use crate::core::BoxFuture;pub use crate::core::Core;pub use crate::error::BreakerState;pub use crate::error::ErrorContext;pub use crate::error::ExecutionError;pub use crate::event::Event;pub use crate::policy::ExecutionPolicy;pub use crate::retry::Backoff;pub use crate::retry::Jitter;pub use crate::retry::Retry;pub use crate::retry::RetryBudget;
Modules§
- attempt
- Per-attempt metadata handed to operation closures.
- breaker
- Circuit breaker: a fast lock-free closed-state gate check (atomic state load) with the bookkeeping mutex taken only on the once-per-call record path.
- builder
- Fluent builder for
ExecutionPolicy. - classify
- Failure classification, kept independent from retry/breaker policy.
- concurrency
- Bounded concurrency: a runtime-agnostic async semaphore (no tokio dependency) plus the explicit saturation policy. Permits release on drop and wake the next waiter.
- core
- Runtime abstraction: clock, sleeping, and RNG behind one object-safe trait.
- error
- Typed failure outcomes with rich, fail-fast diagnostic context.
- event
- Observability hook. Dependency-free:
on_eventis a plain synchronous callback.Eventvalues are constructed only when a hook is registered, so the happy path stays allocation-free when no hook is set. - policy
- The hero type: a reusable, cheaply-cloneable reliability policy.
- retry
- Retry policy, backoff schedules, and jitter.