Function sync

Source
pub fn sync<T>(future: impl Future<Output = T>) -> T
Examples found in repository?
examples/timer.rs (line 83)
82fn main() {
83    println!("{}", sync(do_sth_async(1000)));
84}
More examples
Hide additional examples
examples/join.rs (line 4)
3fn main() {
4    println!("{:?}", sync(join!(fn1(), fn2())));
5}
examples/no_std.rs (line 8)
6fn main() {
7    for _ in 0..10000000 {
8        sync(test());
9    }
10}
examples/main.rs (line 10)
4fn main() {
5    // And there's an async function you want to run:
6    //println!("{}", do_sth_async(1000).await);
7    // but oh no! this doesn't work, because do_sth_async is async and main is sync!
8
9    // Here's where microasync::sync comes into play:
10    println!("{}", sync(do_sth_async(1000)));
11    // It synchronizes a single async function, returning its result as if it was a normal
12    // function. For this, a *tiny*, single-threaded async "runtime" is created, that runs this one
13    // task, and then stops.
14}