#multi-thread #run-time #reactor #future #async

asynk

Multithread asynchronous runtime and reactor

3 releases

new 0.1.2 Nov 6, 2024
0.1.1 Nov 6, 2024
0.1.0 Nov 6, 2024

#376 in Asynchronous

Download history 290/week @ 2024-11-01

290 downloads per month
Used in asynk-hyper

MIT/Apache

26KB
589 lines

asynk

Rust multithread asynchronous runtime and reactor

Example

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);
}

Dependencies

~1.7–9.5MB
~89K SLoC