Skip to main content

offload

Function offload 

Source
pub async fn offload<F>(fut: F) -> F::Output
where F: Future + Send + 'static, F::Output: Send + 'static,
Expand description

Run a future on tokio’s worker pool instead of the calling thread.

Dioxus polls its tasks (use_resource, spawn) on the UI thread, so any CPU spent inside them — sqlx row decoding, response JSON parsing — stalls rendering for that long. Wrapping the future here moves the work to a worker thread; the UI-side task only awaits the join handle. The Send bound is the guardrail: a future that touches a Signal won’t compile.

Dropping the returned future aborts the spawned task, so cancellation passes through: when dioxus drops a superseded use_resource rerun, the offloaded query stops instead of running to completion in the background — the same semantics the un-offloaded future had.

Panics inside the future propagate to the caller unchanged.