Updating to std::future::Future
seanmonstar opened this issue · 17 comments
With std::future::Future
stabilizing in Rust 1.36, it is a goal to upgrade from futures@0.1
to std::future::Future
in the next breaking change (hyper@0.13
).
Status:
I might be missing something, but is there a tracking issue on Tower to support 0.3 futures?
You say you are just considering it, but would TLS (Thread Local Storage, I presume) play well with Tokio's multi-threaded executor and, for example with conditional calls to tokio_threadpool::blocking
in (Body
) Stream
s and Sink
s?
That should be fine. When calling poll
methods, we'd still need to materialize the Context
before doing so, so there'd be no relying on other libraries keeping things on the same thread. It's more just wanting to reduce the noise of having to pass a Context
to many methods of proto::h1::Conn
that don't always need it, but might poll the IO.
Most of the dependencies needed are updated in tokio's std-future branch. Disabling tokio-threadpool and h2 should hopefully be enough to start a branch here.
It's probably not worth figuring out some TLS Context thingy, and just passing the argument everywhere.
#1836 is the PR for this, it's pretty close. Most things work (minus h2), and I have some local work to remove much of added unsafety, which I hope to have ready Monday. I'll likely merge that into master with docs and tests disabled, to allow those things to be worked on in parallel.
Master is now tracking 0.13, and #1836 was merged into it. It lacks HTTP2 support, an unsafe pin audit, and all the tests and examples were disabled, but hopefully those can be worked on in parallel.
Thanks everyone for working on this! I'm a bit confused about one thing though - is the move to std::future::Future
intentionally also a move to async / await? I was assuming I could build a library with MSRV 1.36 that's going to be using hyper 0.13, but a bunch of code has already been committed that relies on #![feature(async_await)]
instead of only the Future
trait. Is it just too much hassle to convert to the new Future
first, and start using async / await later? (which should purely be an implementation detail)
tokio 0.2
uses await
AFAIK.
Thanks. I asked on the tokio Gitter channel; apparently they want to only release 0.2
once async_await is stabilized.
@seanmonstar are there plans to migrate Body
to AsyncRead
instead of being a Stream<Item = Chunk>
? If it uses AsyncRead
I can add async implementations to multipart
and abandon multipart-async
. I'm wondering if I should maintain two different crates anyway as the ecosystem seems to be migrating wholesale to async.
@abonander Might be a tricky tricky to do so for a few reasons:
- Body isn't really a
Stream<Item = Chunk>
, it's aPayload
. - AsyncRead doesn't—to the best of my knowledge—have the equivalent of
Payload::poll_trailers
, which is needed H/2 connections. The closest thing seems to be http-body, but that isn't AsyncRead.
Personally, I'd love to have a shared interface/trait at the moment for the reasons you outlined, but I'm not confident any of the shared interfaces—HttpBody
or AsyncRead
—tick off all the requirements someone might have. Maybe a blanket implementation for either trait could work/bridge some gaps in the interface?
@davidbarsky I mostly meant if there were plans to add the impl even though I used "instead of". I didn't mean removing any other API.
@abonander Ah, sorry about that; I misread what you said. Maybe? I'm not 100% sure how that could be implemented without needing specialization, but I might be missing something!
@davidbarsky how would specialization be necessary? There's only one possible impl, Body
isn't generic. Digging through the code it looks like it uses AsyncRead
underneath and then switches to producing Bytes
in proto::h1::io
.
Are there plans to migrate
Body
toAsyncRead
instead of being aStream<Item = Chunk>
?
[..]
I mostly meant if there were plans to add the impl even though I used "instead of". I didn't mean removing any other API.
No plans so far... Here's some reasons of the top of my head why not to:
- The
Body
cannot freely implementStream
andAsyncRead
. In order to provideAsyncRead
, it would need to add a slot to cache aChunk
, in case theAsyncRead::poll_read
buffer wasn't big enough to copy the full thing. This would make the struct bigger and add another branch toStream::poll_next
. - The
Stream
impl can include more specific errors. I suppose anAsyncRead
could just translate those tostd::io::ErrorKind::Other
, though...
If there are good reasons to consider otherwise, we should open a new specific issue to discuss, ya?
All the original "features" on master now use std::future, so I'm going to close this. Some tests and docs still need updating, thought.