Function delay_timer::prelude::async_spawn_by_smol

source ·
pub fn async_spawn_by_smol<T>(
    future: impl Future<Output = T> + Send + 'static
) -> Task<T> 
where T: Send + 'static,
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.

§Examples

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

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