Function tokio_uring::spawn

source ·
pub fn spawn<T: Future + 'static>(task: T) -> JoinHandle<T::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. When a runtime is shutdown, all outstanding tasks are dropped, regardless of the lifecycle of that task.

This function must be called from the context of a tokio-uring runtime.

Examples

In this example, a server is started and spawn is used to start a new task that processes each received connection.

tokio_uring::start(async {
    let handle = tokio_uring::spawn(async {
        println!("hello from a background task");
    });

    // Let the task complete
    handle.await.unwrap();
});