-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Simplify client doctest with default Runtime::block_on #1565
Conversation
* Gives a path to reuse Client and wait for a Result. * Avoids rt::lazy, from_utf8 and some other noise
Thanks for the detailed PR, I really appreciated it! I'm not sure about (but could be convinced otherwise!) having the docs suggesting that you should reach for Especially since you can easily think that you could use |
Thank you for giving feedback. Firstly, the use of //! *Note*: Using `block_on` (or `run`) will panic if used in an executor,
//! since these methods block. For fully asynchronous client usage, use
//! `spawn` instead. This `block_on` pattern can be applicable as a starting
//! point, in test code, CLI's, or batch processors.
//! See the guide (link) for a fully asynchronous example using `spawn`.
I have also made PR #1568 which uses |
I appreciate several of the word clarifications you've made here. However, I actually think the docs should recommend that a user use As I mentioned in #1568, if the concern is about forgetting to put it in a |
I've attempting a better problem statement in #1571. If replacing |
I found this PR very helpful, I experienced all pain described in #1571 |
Thanks for the efforts to improve the documentation, I greatly appreciate it! I'm going to close this for now, and allow discussion to happen in #1571. If we find ways in that issue to improve things, new PRs can always be submitted. |
The client module level doctest benefits from succinctness more than examples/client.rs and the guide. Here I change it to use
Runtime::block_on()
with the following advantages:Demonstrates blocking wait for a completed
Result<Chunk,Error>
which should remain a common pattern outside of fully-asynchronous servers.Gives a path to reuse the
Client
, which can now outlive job(s) without hangingAvoids
rt::lazy
,from_utf8
and some other unnecessary noiseBelow is the rustdoc, example section output without all of the source comment framing:
Note
tokio::runtime::Runtime
isn't currently re-exported in hyper::rt. I could add it there instead, if desired, though I wonder about the sustainability of this re-export approach? Thetokio::runtime::Runtime::block_on
method was released in tokio 0.1.7, so before merging or releasing this, (I or someone) should increase the patch release of tokio in Cargo.toml. Alternatively, tokio::runtime::current_thread is available in tokio 0.1.6, but my impression is that this runtime is less general purpose than the default runtime.I have some related extensions/changes that I'd like to propose with examples/client and therefore the guide as well, but this doctest is simpler and therefore a good starting point to hopefully get some feedback.