Crates.io | microasync |
lib.rs | microasync |
version | 0.4.2 |
source | src |
created_at | 2022-12-22 15:23:49.74473 |
updated_at | 2023-01-05 12:05:20.640281 |
description | Very small async runner |
homepage | |
repository | https://github.com/tudbut/microasync |
max_upload_size | |
id | 743970 |
size | 11,689 |
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.
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.
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
}
This crate supports a no_std
environment. To do this, enable the no_std
feature of
this crate.
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
.