Skip to main content

spawn_sendable

Function spawn_sendable 

Source
pub fn spawn_sendable<F>(fut: F) -> SendableJoinHandle<<F as Future>::Output> ⓘ
where F: Future + 'static, <F as Future>::Output: Send,
Expand description

Spawns a local future and returns a SendableJoinHandle for its result.

The task is spawned immediately on the current runtime, using crate::spawn_detached and its registered task callbacks. The spawned future need not be Send, but its output must be. Only the returned handle may be moved to another thread; the task stays on its original runtime, which must keep being driven.

Dropping the handle detaches the task unless cancel_on_drop is enabled. Use cancel to request cancellation explicitly.

Awaiting the handle yields the output or crate::JoinError if the task ends without one, for example on panic or runtime shutdown. Task panics follow the runtime’s usual behavior.

§Panics

Panics outside a runtime context that supports crate::spawn_detached.