Skip to content

Joining futures #75

Closed
Closed
@CarlosLanderas

Description

@CarlosLanderas

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());
    });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions