Skip to content

Joining futures #75

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

Closed
CarlosLanderas opened this issue Aug 18, 2019 · 3 comments
Closed

Joining futures #75

CarlosLanderas opened this issue Aug 18, 2019 · 3 comments

Comments

@CarlosLanderas
Copy link

CarlosLanderas commented Aug 18, 2019

Hello, sorry for the ignorance, but I would like to know if this crate has available some
macro / mechanism to join futures so they can ran concurrently like futures crate has.

#![feature(pin, async_await, futures_api)]
use async_std::io;
use async_std::task;
use serde_derive::Deserialize;

#[macro_use]
extern crate futures;

#[derive(Deserialize, Debug)]
struct Post {
    #[serde(rename = "userId")]
    user_id : usize,
    id: usize,
    title: String,
    completed: bool
}

fn main() {
    task::block_on(async {
        let post_fut  = surf::get("https://jsonplaceholder.typicode.com/todos/1").recv_json::<Post>();
        let post2_fut = surf::get("https://jsonplaceholder.typicode.com/todos/2").recv_json::<Post>();
        let (result1, result2 ) = join!(post_fut, post2_fut);
        println!("{:?}", result1.unwrap());
        println!("{:?}", result2.unwrap());
    });
}
@skade
Copy link
Collaborator

skade commented Aug 18, 2019

Hi, we recommend using the futures crate for that, currently.

For our current discussion on adding join and select, see #14. Short summary: we're not sure of what currently exists is stable enough or if we can find our own useful design.

@CarlosLanderas
Copy link
Author

Thanks @skade, I'll follow the discussion.

@skade
Copy link
Collaborator

skade commented Aug 18, 2019

You're welcome :).

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

No branches or pull requests

2 participants