Skip to main content

Module task

Module task 

Source
Expand description

One tokio task type for many spawn sites.

tokio::spawn and tokio::task::spawn_blocking are generic over the future / closure, and each type compiles its own task machinery (poll, harness, join handle: about 1.9 KiB per call site on x86_64). Stores run every operation on the blocking pool, so a store with 30 methods paid for 30 task types. spawn and spawn_blocking erase the future / closure behind a box (one allocation, which a spawn makes anyway), so the machinery exists once for each.

Functionsยง

spawn
Spawns future on the current runtime, like tokio::spawn.
spawn_blocking
Runs job on the blocking pool, like tokio::task::spawn_blocking.