-
Notifications
You must be signed in to change notification settings - Fork 310
util: Add ReadyAnd to do what Ready should do #427
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
Conversation
`ServiceExt::ready` says that it produces "A future yielding the service when it is ready to accept a request." This is not true; it does _not_ yield the service when it is ready, it yields unit. This makes it impossible to chain service ready with service call, which is sad. This PR adds `ready_and`, which does what `ready` promised. It also deprecates `ready` with the intention that we remove `ready` in a future version, and make the strictly more general `ready_and` take its place. We can't do it now since it's not a backwards-compatible change even though it _probably_ wouldn't break any code. The PR also updates the docs so that they reflect the observed behavior.
where | ||
T: Service<Request>, | ||
{ | ||
#[allow(missing_docs)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we just add docs now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always found documentation on new
super weird since it becomes so trivial (for simple cases like this). I guess I could add something, but my inclination is to leave it 😅
pub struct Ready<'a, T, Request> { | ||
inner: &'a mut T, | ||
/// `ReadyOneshot` values are produced by `ServiceExt::ready_oneshot`. | ||
pub struct ReadyOneshot<T, Request> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want a manual clone impl if T is clone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first instinct says no — it should be rare that you'd want to clone a ReadyOneshot
as opposed to cloning the underlying Service
. If you did, that's probably not what you meant to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments, nothing blocking :)
This PR renames: - `ServiceExt::ready_and` to `ServiceExt::ready` - the `ReadyAnd` future to `Ready` - the associated documentation to refer to `ServiceExt::ready` and `ReadyAnd`. This PR deprecates: - the `ServiceExt::ready_and` method - the `ReadyAnd` future These can be removed in Tower 0.5. My recollection of the original conversation surrounding the introduction of the `ServiceExt::ready_and` combinator in #427 was that it was meant to be a temporary workaround for the unchainable `ServiceExt::ready` combinator until the next breaking release of the Tower crate. The unchainable `ServiceExt::ready` combinator was removed, but `ServiceExt::ready_and` was not renamed. I believe, but am not 100% sure, that this was an oversight.
ServiceExt::ready
says that it produces "A future yielding the servicewhen it is ready to accept a request." This is not true; it does not
yield the service when it is ready, it yields unit. This makes it
impossible to chain service ready with service call, which is sad.
This PR adds
ready_and
, which does whatready
promised. It alsodeprecates
ready
with the intention that we removeready
in a futureversion, and make the strictly more general
ready_and
take its place.We can't do it now since it's not a backwards-compatible change even
though it probably wouldn't break any code.
The PR also updates the docs so that they reflect the observed behavior.