https://github.com/krypt0nn/wait_not_await
Simple awaiter implementation in 🦀 Rust
https://github.com/krypt0nn/wait_not_await
async rust
Last synced: about 1 year ago
JSON representation
Simple awaiter implementation in 🦀 Rust
- Host: GitHub
- URL: https://github.com/krypt0nn/wait_not_await
- Owner: krypt0nn
- License: mit
- Created: 2022-03-21T19:42:04.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-01-27T20:39:09.000Z (over 3 years ago)
- Last Synced: 2025-04-14T06:41:40.034Z (about 1 year ago)
- Topics: async, rust
- Language: Rust
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
🦀 wait_not_await
Simple awaiter implementation in Rust
## Examples
### Await as a variable
```rs
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);
}
```
### Await with functions
```rs
use std::time::Duration;
use wait_not_await::Await;
fn async_hello_world() -> Await {
Await::new(move || {
std::thread::sleep(Duration::from_secs(2));
"Hello, World!".to_string()
})
}
println!("{}", async_hello_world().wait(None).unwrap());
```
### Await result handling
```rs
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);
});
```
### Await loop with result
```rs
use std::time::Duration;
use wait_not_await::Await;
fn async_hello_world() -> Await {
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](https://github.com/krypt0nn)
Licensed under [MIT](LICENSE)