Skip to main content

launchBlocking

Function launchBlocking 

Source
pub fn launchBlocking<T>(
    work: impl FnOnce() -> T + Send + 'static,
    on_ui: impl FnOnce(Result<T, BlockingError>) + 'static,
) -> Result<TaskHandle, BlockingError>
where T: Send + 'static,
Expand description

Starts blocking work and delivers its result on the current runtime’s UI thread. A full queue waits asynchronously inside the runtime-owned task. Execution errors are delivered to on_ui; only a missing runtime is returned immediately without invoking the callback.

The runtime owns the returned task until completion. Calling its cancel method, or dropping the runtime, cancels waiting work and the callback. For screen ownership, prefer rememberCoroutineScope().launch with withBlocking. Without a live runtime this returns NoRuntime.