Function smol::spawn

source ·
pub fn spawn<T: Send + 'static>(
    future: impl Future<Output = T> + Send + 'static
) -> Task<T>
Expand description

Spawns a task onto the global executor (single-threaded by default).

There is a global executor that gets lazily initialized on first use. It is included in this library for convenience when writing unit tests and small programs, but it is otherwise more advisable to create your own Executor.

By default, the global executor is run by a single background thread, but you can also configure the number of threads by setting the SMOL_THREADS environment variable.


let task = smol::spawn(async {
    1 + 2

smol::block_on(async {
    assert_eq!(task.await, 3);