Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry: Change Policy to accept &mut self #681

Merged
merged 10 commits into from
Aug 23, 2022
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Eliza Weisman <[email protected]>
  • Loading branch information
LucioFranco and hawkw authored Aug 22, 2022
commit b98f5380d304fcb415f3fb634400428a593ddb2c
24 changes: 16 additions & 8 deletions tower/src/retry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@ pin_project! {
///
/// # Clone
///
/// This middleware requires that the `Service` is `Clone` due to requirements
/// of `'static` futures. To easily add `Clone` to your service you can
/// use the `Buffer` middleware.
/// This middleware requires that the inner `Service` implements [`Clone`],
/// because the `Service` must be stored in each [`ResponseFuture`] in
/// order to retry the request in the event of a failure. If the inner
/// `Service` type does not implement `Clone`, the [`Buffer`] middleware
/// can be added to make any `Service` cloneable.
///
/// The `Policy` is also required to implement `Clone`. This middleware will
/// clone the policy for each _request session_. This means one instance
/// of the policy will exist for one request and its subsequent retries only.
/// This means the mutable reference is only for that session and if you want
/// to share data between request sessions then you will need to `Arc<Mutex<...>`.
/// [`Buffer`]: crate::buffer::Buffer
///
/// The `Policy` must also implement `Clone`. This middleware will
/// clone the policy for each _request session_. This means a new clone
/// of the policy will be created for each initial request and any subsequent
/// retries of that request. Therefore, any state stored in the `Policy` instance
/// is for that request session only. In order to share data across request
/// sessions, that shared state may be stored in an [`Arc`], so that all clones
/// of the `Policy` type reference the same instance of the shared state.
///
/// [`Arc`]: std::sync::Arc
#[derive(Clone, Debug)]
pub struct Retry<P, S> {
policy: P,
Expand Down
3 changes: 2 additions & 1 deletion tower/src/retry/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ pub trait Policy<Req, Res, E> {
///
/// If the request *should* be retried, return `Some` future that will delay
/// the next retry of the request. This can be used to sleep for a certain
/// duration or resolve right away.
/// duration, to wait for some external condition to be met before retrying,
/// or resolve right away, if the request should be retried immediately.
///
/// ## Mutating Requests
///
Expand Down