compio_runtime

Function spawn

Source
pub fn spawn<F: Future + 'static>(future: F) -> JoinHandle<F::Output>
Expand description

Spawns a new asynchronous task, returning a Task for it.

Spawning a task enables the task to execute concurrently to other tasks. There is no guarantee that a spawned task will execute to completion.

let task = compio_runtime::spawn(async {
    println!("Hello from a spawned task!");
    42
});

assert_eq!(
    task.await.unwrap_or_else(|e| std::panic::resume_unwind(e)),
    42
);

§Panics

This method doesn’t create runtime. It tries to obtain the current runtime by Runtime::with_current.