#async #future #await #thread


Just some macros to emulate the Async and Await :)

5 releases

Uses old Rust 2015

0.2.1 Sep 13, 2016
0.2.0 Sep 13, 2016
0.1.2 Mar 11, 2016
0.1.1 Sep 8, 2015
0.1.0 Sep 8, 2015

#309 in Asynchronous

31 downloads per month


64 lines



Just two macros to emulate a simple Async and Await using Futures (provided by eventual).


This is available in crates.io. Add this to your Cargo.toml:

async-await = "0.1.2"


Here is a simple example, you need to do the #[macro_use] and use async_await::*; because of the expansion of the macros :)

extern crate async_await;

use async_await::*;

fn main() {
    let computation = async!{"Hello world!"};
    println!("{}", await!(computation));

Another example using hyper, a shared client and a block in async :)

extern crate async_await;
extern crate hyper;

use std::io::Read;
use std::sync::Arc;

use async_await::*;

use hyper::Client;
use hyper::header::Connection;

fn main() {
    let client = Arc::new(Client::new());

    let client_comp = client.clone();
    let computation = async!{{
        let mut res = client_comp.get("http://rust-lang.org/")
        let mut body = String::new();
        res.read_to_string(&mut body).unwrap();

    println!("Before await!");
    println!("{}", await!{computation});
    println!("After await!");

You can also provide a default value in case that the computation fails:

extern crate async_await;

use async_await::*;

fn main() {
    let computation = async!{panic!(":()")};
    assert_eq!("Recovered!", await!{computation, "Recovered!"});


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.