Skip to main content

offload

Function offload 

Source
pub async fn offload<F, T>(f: F) -> T
where F: FnOnce() -> T + Send + 'static, T: Send + 'static,
Expand description

Run f off the orchestrator thread and await its result.

Wrap CPU-bound or blocking work in offload(...) and .await it: the orchestrator stays free to keep polling — including the system lane — while the work runs elsewhere, so interrupt barge-in stays responsive.

§Native

Runs f on a fresh std::thread and returns its result over a futures::channel::oneshot. Runtime-agnostic and tokio-free; a runtime adapter can later back this with a pooled spawn_blocking.

Dropping the returned future before it resolves detaches the worker thread — it still runs to completion, but its result is discarded. If f panics, the worker unwinds and drops the sender; awaiting the returned future then panics (a fresh panic noting the worker produced no result — the original payload is not propagated).