Skip to content

Instantly share code, notes, and snippets.

@pimeys
Created June 28, 2019 14:27
Show Gist options
  • Save pimeys/0ad986fc757406b7c009318dc7458589 to your computer and use it in GitHub Desktop.
Save pimeys/0ad986fc757406b7c009318dc7458589 to your computer and use it in GitHub Desktop.
#![feature(async_await, await_macro)]
#![recursion_limit = "128"]
use futures01::future::lazy;
use futures03::future::{FutureExt, TryFutureExt};
pub struct Server {
name: String,
}
impl Server {
async fn get_name(&self) -> String {
self.name.clone()
}
async fn print_name(&self) {
let name = self.get_name().await;
println!("Hello, world! Your name is {}!", name);
}
}
fn main() {
let server = Server {
name: String::from("Musti"),
};
let fut = server.print_name().unit_error().boxed().compat();
tokio::run(fut);
}
@pimeys
Copy link
Author

pimeys commented Jun 28, 2019

#![feature(async_await, await_macro)]
#![recursion_limit = "128"]

use futures03::executor::ThreadPool;

pub struct Server {
    name: String,
}

impl Server {
    async fn get_name(&self) -> String {
        self.name.clone()
    }

    async fn print_name(&self) {
        let name = self.get_name().await;
        println!("Hello, world! Your name is {}!", name);
    }
}

fn main() {
    let server = Server {
        name: String::from("Musti"),
    };
    let mut pool = ThreadPool::new().unwrap();

    pool.run(server.print_name());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment