pub fn spawn<F: Future + 'static>(future: F) -> JoinHandle<F::Output> ⓘExpand description
Spawns a new asynchronous task, returning a JoinHandle 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.
use compio_runtime::ResumeUnwind;
let task = compio_runtime::spawn(async {
println!("Hello from a spawned task!");
42
});
assert_eq!(
task.await.resume_unwind().expect("shouldn't be cancelled"),
42
);§Panics
This method doesn’t create runtime. It tries to obtain the current runtime
by Runtime::with_current.