Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upDetermine integration story for Futures 0.3 #26
Comments
aturon
added
the
futures
label
Jul 23, 2018
This comment has been minimized.
This comment has been minimized.
|
Personally, I think we should get a shim library working ASAP. I believe that's the shortest path to getting Futures 0.3 usable, and immediately makes it possible to use the whole ecosystem. I think it will also be important for existing production uses of Futures 0.1. As time passes, we can also add direct 0.3 support in libraries (under a flag), which will improve the overall user experience. The overall approach in the existing shim seems like a good starting point to me. However, I'd prioritize ergonomics a bit, and instead of having methods like
and so on. I'm pretty sure this is feasible. At the very least, though, having a short, consistent method name like I also think we should land this compatibility layer directly in the futures-util 0.3 crate. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
seanmonstar
commented
Jul 24, 2018
|
That sounds excellent to me! Besides centralizing maintenance while experimenting, having a shim will be a big help to the community, as it allows people to upgrade dependencies in steps, instead of requiring all-or-nothing. |
This comment has been minimized.
This comment has been minimized.
|
I absolutely agree that we should develop a shim and that it should be officially supported.
|
This comment has been minimized.
This comment has been minimized.
|
@tinaun has put together an early prototype of such a shim crate. @MajorBreakfast or @cramertj, would one of you be able to give a review for the overall approach? |
This comment has been minimized.
This comment has been minimized.
tinaun
commented
Jul 24, 2018
•
|
one thing about the "one type" approach - from my experiments it seems to add about a second or two to compile times in my small tests vs one type each for 0.3 -> 0.1 and 0.1 -> 0.3 #![feature(async_await, await_macro)]
use hyper::Client;
use hyper::rt::Stream;
use futures_playground::{Compat01, Compat03, ExecCompat};
use tokio::runtime::Runtime;
use std::io::{self, prelude::*};
fn main() {
let client = Client::new();
let fut = client.get("http://httpbin.org/ip".parse().unwrap()).compat();
let fut = async {
let res = await!(fut).unwrap();
println!("{}", res.status());
// println!("uncomment me!");
await!(res.into_body().for_each(|chunk| {
io::stdout().write_all(&chunk)
.map_err(|e| panic!("example expects stdout is open, error={}", e))
}).compat());
};
let mut rt = Runtime::new().unwrap();
let fut = fut.compat(rt.executor().compat());
let _ = rt.block_on(fut);
}compiles in about 6.5 seconds with two Compat types, and 8 seconds with one Compat type even 6.5 seconds still feels pretty bad for a small an example as this - but there sure is a lot going on! |
This comment has been minimized.
This comment has been minimized.
|
@tinaun I kinda like the one type approach: We should try it and see if it works out. If compilation time really turns out to be an issue, we can change it. Here are some ideas from my side: let fut03 = /* Some `TryFuture03<Ok = T, Error = E> + Unpin` */;
let both = fut03.compat(); // Future03<Result<T, E>> + Unpin and
// Future01<Item = T, Error = E>
let fut03 = /* Some `Future03<Output = T> + Unpin` */;
let both = fut03.never_error().compat(); // Future03<Result<T, Never>> + Unpin and
// Future01<Item = T, Error = Never>
let fut03 = /* Some `Future03<Output = T>` */;
let both = fut03.never_error().boxed().compat(); // Future03<Result<T, Never>> + Unpin and
// Future01<Item = T, Error = Never>
// ---
let fut01 = /* Some `Future01<Item = T, Error = E>` */;
let both = fut01.compat(); // Future03<Result<T, E>> + Unpin and
// Future01<Item = T, Error = E>
let fut01: = /* Some `Future01<Item = T, Error = Never>` */;
let fut03 = fut01.compat().unwrap(); // Future03<Output = T>New combinators:
Note: What do you think? Edit: Changed @tinaun Do you want to open a PR? (Only if you want!) Some suggestions for the PR:
|
This comment has been minimized.
This comment has been minimized.
tinaun
commented
Jul 24, 2018
|
ok, i can do that - do you have a preferred way of handling 0.3 Executors? to wrap a Future03 in a Future01 there needs to be an Executor to create a Context - is passing it in the combinator fine? is there a better way to do it? |
This comment has been minimized.
This comment has been minimized.
|
@tinaun I think we need the param because there is AFAIK no mechanism to get the executor from the The code by @seanmonstar uses an exec param as well Let's use a param for now. Maybe we can add an executor to the 0.1 |
This comment has been minimized.
This comment has been minimized.
One thing is that |
This comment has been minimized.
This comment has been minimized.
tinaun
commented
Jul 27, 2018
•
|
ideally a tokio shim would allow people to write futures 0.3 + tokio 0.1 code which could be upgraded to use a future version of tokio with default futures 0.3 support as painlessly as possible, i wouldn't want libraries to get stuck in a hopefully intermediate state |
This comment has been minimized.
This comment has been minimized.
luser
commented
Jul 30, 2018
|
FWIW, if anyone wants to see how this pans out in a nontrivial real-world project, I'd love to see this in sccache. We're using a number of tokio crates there along with hyper (as a client). It would be great to figure out the upgrade path to futures 0.3 for that project! |
This comment has been minimized.
This comment has been minimized.
|
@luser great idea! I think @alexcrichton would be able to help mentor such an effort, as well. |
This comment has been minimized.
This comment has been minimized.
|
I'm gonna close this out -- we now have multiple compatibility options! |
aturon commentedJul 23, 2018
In particular: should we follow a 0.1 <-> 0.3 shim approach for now? Or should we consider direct implementation behind a feature flag for key libraries?