microasync

Crates.iomicroasync
lib.rsmicroasync
version0.4.2
sourcesrc
created_at2022-12-22 15:23:49.74473
updated_at2023-01-05 12:05:20.640281
descriptionVery small async runner
homepage
repositoryhttps://github.com/tudbut/microasync
max_upload_size
id743970
size11,689
Tud (TudbuT)

documentation

README

microasync

MicroAsync is a tiny async "runtime" for rust, created when I was very bothered by a library that was fully async, but my code was all written synchronously.

Use-case

Let's say you have a sync function here, and there's an async function you want to run, but oh no! It doesn't work, because the function is async and your function isn't!

Here's where microasync::sync comes into play.

It synchronizes a single async function, returning its result as if it was a normal function. For this, a tiny, single-threaded async "runtime" is created, that runs this one task, and then stops.

Example

use microasync::sync;

fn main() {
    //println!("{}", do_sth_async(1000).await);

    println!("{}", sync(do_sth_async(1000)));
}

async fn add_async(a: i32, b: i32) -> i32 {
    a + b
}

async fn do_sth_async(i: i32) -> i32 {
    add_async(i, i * 4).await
}

No STD? No problem.

This crate supports a no_std environment. To do this, enable the no_std feature of this crate.

Joining

Multiple futures can be joined using the join!() macro, which will effectively parallelize many futures into one, which can then, once again, be run by sync(). This allows most things to be implementable using MicroAsync.

This feature can be deactivated by using the no_joiner feature flag.

A demo of this feature can be found in examples/join.rs.

Commit count: 21

cargo fmt