Crates.io | wait_not_await |
lib.rs | wait_not_await |
version | 0.2.1 |
source | src |
created_at | 2022-03-21 19:58:40.71872 |
updated_at | 2022-03-28 09:53:23.844038 |
description | Simple awaiter implementation |
homepage | |
repository | https://github.com/krypt0nn/wait_not_await |
max_upload_size | |
id | 554286 |
size | 8,652 |
Simple awaiter implementation in Rust
use std::time::Duration;
use wait_not_await::Await;
let mut awaiter = Await::new(move || {
std::thread::sleep(Duration::from_secs(3));
"Hello, Wolrd!".to_string()
});
if let Some(result) = awaiter.wait(None) {
println!("Result: {}", result);
}
use std::time::Duration;
use wait_not_await::Await;
fn async_hello_world() -> Await<String> {
Await::new(move || {
std::thread::sleep(Duration::from_secs(2));
"Hello, World!".to_string()
})
}
println!("{}", async_hello_world().wait(None).unwrap());
use std::time::Duration;
use wait_not_await::Await;
let awaiter = Await::new(move || {
std::thread::sleep(Duration::from_secs(3));
"Hello, Wolrd!".to_string()
});
awaiter.then(move |result| {
println!("Task result: {}", result);
});
use std::time::Duration;
use wait_not_await::Await;
fn async_hello_world() -> Await<String> {
Await::new(move || {
std::thread::sleep(Duration::from_secs(2));
"Hello, World!".to_string()
})
}
let mut awaiter = async_hello_world();
let mut i = 1;
while let None = awaiter.result() {
println!("Waiting for result: {}", i);
i += 1;
}
println!("{}", awaiter.result().unwrap());
Author: Nikita Podvirnyy
Licensed under MIT