Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Are you using this crate? #111

Open
withoutboats opened this issue Oct 24, 2018 · 20 comments
Open

Are you using this crate? #111

withoutboats opened this issue Oct 24, 2018 · 20 comments

Comments

@withoutboats
Copy link
Collaborator

This crate has been in maintenance mode (and pitifully maintained) for several months. However, at this point, I think it might be time to straight deprecate it. There are now bridges between the futures 0.3 version (which is used by the async/await native syntax) and the futures 0.1 version (which is used by libraries like tokio and hyper) provided in the tokio-async-await crate.

So I'm asking: are you still using this crate? If so, what is stopping you from moving to native syntax?

@joepie91
Copy link

I opted for not using this package due to the limitations stated in the README, and stuck with combinator syntax instead.

However, it is news to me that there is an alternative option at all. Despite quite a lot of searching, I've not been able to find anything about "native async/await syntax" or how to use it with futures, anywhere - just mentions of it being worked on. Could you elaborate on this?

@withoutboats
Copy link
Collaborator Author

Async/await is implemented on nightly, for example:

#![feature(async_await, futures_api, await_macro)]

use std::future::Future;

async fn foo<F: Future<Output = i32> + 'static>(x: &i32, future: F) -> i32 {
    let y = await!(future);
    *x + y
}

@joepie91
Copy link

Thanks! Is there any formal documentation about this feature anywhere?

I'm particularly interested in the limitations of it (if any), and I suspect that many of the users of this crate also wouldn't be aware of this, and might continue using this crate for that reason. Even searching specifically for those feature names, I can't find anything that looks comprehensive or authorative.

@withoutboats
Copy link
Collaborator Author

Thanks! Is there any formal documentation about this feature anywhere?

There's an RFC but that's about it so far. rust-lang/rfcs#2394

@mikong
Copy link

mikong commented Nov 3, 2018

I was looking for information about async/await after watching a talk about Tokio, and this repo is the first relevant result in my search. It wasn't immediately clear if this is being deprecated (until I checked the issues). I think it would be great if information about where to check instead is shown at the very top of the README (link to the RFC), and maybe a link to this issue for people who are using this crate.

@alex
Copy link
Contributor

alex commented Nov 11, 2018

I'm still using this crate. I suspect I can move to native async/await, however I'm running into exciting mismatches between await!() which wants a std::future::Future, and futures from hyper which are future::Future. Is there any documentation on what you need to do to bridge this?

@withoutboats
Copy link
Collaborator Author

Is there any documentation on what you need to do to bridge this?

There's some compatibility shims in the futures crate, and an even more convenient shim in tokio-async-await, which replaces the await! macro from std with one that can await both futures 0.3 and futures 0.1.

@alex
Copy link
Contributor

alex commented Nov 12, 2018 via email

@withoutboats
Copy link
Collaborator Author

Are you looking at the right futures crate? You want the futures-preview crate (the main futures is just the old 0.1 version until we release futures 0.3 properly). It has a compat module. The other crate I mentioned with the await macro is here.

@Nemo157
Copy link
Contributor

Nemo157 commented Nov 12, 2018

@alex there's also an unreleased blog post about the compat shims. The blog post is based on a slightly older version where the TryFutureExt::compat method took a spawner, that's now removed since std::futures doesn't natively support spawning, but the rest is still relevant

@alex
Copy link
Contributor

alex commented Nov 12, 2018 via email

@vorot93
Copy link

vorot93 commented Dec 6, 2018

Is there an #[async_stream] replacement out there?

@ajsyp
Copy link

ajsyp commented Dec 12, 2018

I agree with @vorot93: I depend on this crate quite a bit because, as far as I can tell, there is no other way forward that replaces #[async_stream], which I use extensively. Would love to switch over to the new built-in async/await syntax and futures 0.3, though. @withoutboats -- do you know of a way to write native async streams? Or a compatibility shim for "async generators" (which yield stream elements and which could await! on other futures)?

@jimmycuadra
Copy link

jimmycuadra commented Dec 13, 2018

I'm also unclear how we're supposed to approach async for loops with futures-preview, as my understanding was that is not part of what's being moved into std.

Edit:

As far as I can tell, the way to do this is what's shown in this blog post about Tokio's async/await support: https://tokio.rs/blog/2018-08-async-await/

tl;dr: Await a single future from a stream using a while loop.

@withoutboats
Copy link
Collaborator Author

Yes the way to write a for loop is to await the next future in a while loop. There's no replacement for asnyc_stream on futures 0.3 right now.

@ajsyp
Copy link

ajsyp commented Dec 13, 2018

In that case, can we leave the crate un-deprecated until a replacement is available?

@jethrogb
Copy link

jethrogb commented Mar 5, 2019

So I'm asking: are you still using this crate?

Yes.

If so, what is stopping you from moving to native syntax?

Nothing, it was just really hard to find out what the "correct" way to do things is when I started a new project about a month ago. This crate popped up as a reasonably working option. Maybe do a new crates.io release and recommend migration in the readme?

@vorot93
Copy link

vorot93 commented Mar 5, 2019

@withoutboats @ajsyp
I have created an async_stream alternative based on futures 0.3 and generators. Hopefully it may put this package to rest.

https://github.com/vorot93/gen-stream

@ajsyp
Copy link

ajsyp commented Mar 6, 2019

@vorot93 Great! I saw your post on reddit earlier, will definitely give this a shot.

@taiki-e
Copy link

taiki-e commented Apr 7, 2019

I have a patch to support #[async] for and #[async_stream] in futures 0.3: rust-lang/futures-rs@master...taiki-e:async-stream

Currently, this is blocked in work for the futures_api stabilization (rust-lang/futures-rs#1514), but after the futures 0.3.0-alpha.14 is released, I will open a PR for this.

However, this patch is too big and will take a long time to review, so I may prefer to add only #[async] for to futures-rs (rust-lang/futures-rs@master...taiki-e:for-await) and support #[async_stream] in the other repository.

In any case, we can use these features in the not‐too‐distant future.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants