twizzler_async

Function run

source
pub fn run<T>(future: impl Future<Output = T>) -> T
Expand description

Runs executors.

We run both the thread-local executor and the global executor, and also check for timer events. If we cannot make progress, we call the reactor, which handles waiting and waking up on crate::Async and crate::AsyncDuplex objects for use in externally signaled events that control non-blocking closures’ readiness.

§Examples

// Run executors on the current thread.
run(async {
    println!("Hello!");
});

Multi-threaded:

use futures::future;
let num_threads = 4;
for _ in 0..num_threads {
    // Spawn a pending future.
    std::thread::spawn(|| twizzler_async::run(future::pending::<()>()))
}

twizzler_async::block_on(async {
    twizzler_async::Task::spawn(async {
        println!("Hello from executor thread!");
    })
    .await;
});