Crates.io | asynk |
lib.rs | asynk |
version | 0.1.2 |
source | src |
created_at | 2024-11-06 07:05:56.95444 |
updated_at | 2024-11-06 16:04:39.236895 |
description | Multithread asynchronous runtime and reactor |
homepage | |
repository | https://github.com/bells307/asynk-rt |
max_upload_size | |
id | 1437831 |
size | 42,254 |
Rust multithread asynchronous runtime and reactor
use futures::future;
use futures_timer::Delay;
use std::{
sync::{
atomic::{AtomicU32, Ordering},
Arc,
},
time::Duration,
};
fn main() {
asynk::builder().build().unwrap();
asynk::block_on(main_future()).unwrap();
}
async fn main_future() {
let val = Arc::new(AtomicU32::new(0));
let expected_val = 10_000;
let handles = (0..expected_val)
.map(|_| Arc::clone(&val))
.map(|val| {
asynk::spawn(async move {
// some computations ...
Delay::new(Duration::from_secs(1)).await;
val.fetch_add(1, Ordering::SeqCst);
})
})
.collect::<Vec<_>>();
future::join_all(handles).await;
assert_eq!(val.load(Ordering::SeqCst), expected_val);
}