Simplify client doctest with default Runtime::block_on #1565
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.