Skip to content
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

Compat blog post take 2 #1357

Merged
merged 11 commits into from
Apr 18, 2019
Merged

Compat blog post take 2 #1357

merged 11 commits into from
Apr 18, 2019

Conversation

Nemo157
Copy link
Member

@Nemo157 Nemo157 commented Nov 29, 2018

Replacement for #1226 (@MajorBreakfast I hope you're ok with me taking this over).

I still want to add some info on the spawn and IO compat that's been added since this was originally written, and I need to actually test the snippets against the new API. Should get to that over the weekend at some point.

MajorBreakfast and others added 6 commits August 26, 2018 21:30
@cramertj
Copy link
Member

cramertj commented Dec 3, 2018

Aside from the one nit and updating to add IO/spawn info, this LGTM so far!

@LucioFranco
Copy link
Member

One, thing that might be useful to add is something about sink support with tokio. As I used this post to convert my project to async/await. I was a bit confused on how to approach sinks. I ended up with using some of the tokio compat features. So maybe a mention about it would be helpful imo.

@Nemo157
Copy link
Member Author

Nemo157 commented Dec 4, 2018

@LucioFranco yeah, probably worth adding a section about Sink. Currently it's possible to wrap a 0.3 Sink into a 0.1 Sink, but not the other direction. I will also open an issue about whether it's possible to add that additional conversion, I couldn't think of an easy way when implementing the current Sink compat stuff but maybe it's possible with a little bit of extra runtime cost.

Add IO and spawning sections, update final example to use IO
compatibility.
@Nemo157
Copy link
Member Author

Nemo157 commented Dec 4, 2018

Added info on Spawn, IO and Sink, and updated the final example to use the new IO compat layer.

@Nemo157 Nemo157 changed the title WIP: Compat blog post take 2 Compat blog post take 2 Dec 4, 2018
@LucioFranco
Copy link
Member

@Nemo157 Great! I just took a look at it again, it def clears some things up. I am still slightly struggling to understand where the TokioDefaultSpawner fits into the whole picture. Also, I think the fact that there is no 0.1 -> 0.3 is a bigger issue for people using tokio. So maybe might be worthwhile to be more upfront about that?

This btw is my hacky solution to using std await and UdpFramed from tokio. I would be interested to help build out some of the sink compat stuff.

while let Some(msg) = await!(rx.next()) {
    println!("Sending: {:?}", msg);

    {
        use tokio::prelude::SinkExt;
        if let Err(e) = await!(sink.send_async((msg, to))) {
            println!("Sending message: {}", e);
        }
    }
}

I would also maybe add a cargo.toml snippet for the example so that its easier for people to try it out.

@Nemo157
Copy link
Member Author

Nemo157 commented Dec 4, 2018

@LucioFranco thanks, those are some good points. I think an example of using TokioDefaultSpawner is probably the easiest way to show what it’s useful for. I can expand a bit more on the Sink situation as well. And having the Cargo.toml for the example would definitely be worth it.

@Nemo157
Copy link
Member Author

Nemo157 commented Dec 28, 2018

Sorry about the big delay on this again, I'll try and finish this off before 2019!

@Nemo157
Copy link
Member Author

Nemo157 commented Mar 5, 2019

Updated now that Sink is supported and TokioDefaultSpawner was removed, also uses the new methods from #1469 for consistency so is blocked on that being merged and a new release.

Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read through it again looks good!

@corbinu
Copy link

corbinu commented Mar 6, 2019

@Nemo157 Read through it as somebody outside of the working team and just excited about async/await. It looks great and is easy to understand. Super excited!

@archseer
Copy link
Contributor

How would one go about using select! with tokio compatibility? I ran into some problems because select-macro seems to call out to the stdlib/futures implementations so it doesn't hit the tokio await wrapper.

@Nemo157
Copy link
Member Author

Nemo157 commented Mar 24, 2019

@archseer I have no real experience using Tokio's await! macro, but you can just use the futures 0.1 -> 0.3 compat methods to convert Tokio's futures into std futures so that they work with std::await!, something like

use futures::future::FutureExt;
use futures::compat::Future01CompatExt;

select! {
        foo = some_tokio_future().compat().fuse() => { ... },
        bar = some_other_tokio_future().compat().fuse() => { ... },
};

@Nemo157
Copy link
Member Author

Nemo157 commented Apr 18, 2019

@cramertj I've checked the example code works with the new release and all the links are correct, I think this is good to publish finally 😁

@cramertj
Copy link
Member

Nice!

@cramertj cramertj merged commit e692abb into rust-lang:gh-pages Apr 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants