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

docs: provide an example to explain the cloning inner services #762

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tower-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ use std::task::{Context, Poll};
///
/// Services are permitted to panic if `call` is invoked without obtaining `Poll::Ready(Ok(()))`
/// from `poll_ready`. You should therefore be careful when cloning services for example to move
/// them into boxed futures. Even though the original service is ready, the clone might not be.
/// them into boxed futures. Even though the original service is ready, the clone might not be,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how ConcurrencyLimit exemplifies what this docs section is trying to convey. If you're referring to the fact that cloning an inner ConcurrencyLimit service resets the permit to unacquired and that poll_ready acquires it, that will only be understood by readers who have read ConcurrencyLimit's source code.

/// as in the case of the [`ConcurrencyLimit`] middleware.
///
/// [`ConcurrencyLimit`]: crate::limit::ConcurrencyLimit#impl-Clone
///
/// Therefore this kind of code is wrong and might panic:
///
Expand Down