Skip to main content

spawn_task

Function spawn_task 

Source
pub fn spawn_task<F: FnOnce() + Send + 'static>(
    _gate: RuntimeGate,
    f: F,
) -> TaskHandle
Expand description

Spawns f onto the fiber pool and returns a joinable TaskHandle.

Fast path — closures ≤ POOL_INLINE_CAPACITY bytes and ≤ 16-byte alignment: drawn from the lock-free POOL_HEAD pool (one LOCK CMPXCHG8B pair, no malloc).

Fallback path — larger or over-aligned closures: one Box allocation via the global allocator, same as before the pool existed.

dtact dispatches the closure to whichever worker is currently coldest. Drop the handle if you don’t need to wait — fibers run to completion regardless. Call join to block until the fiber finishes.