launch

open fun launch(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, withLoading: MutableStateFlow<Int>? = loading, onError: suspend (Throwable) -> Unit? = null, block: suspend CoroutineScope.() -> Unit): Job

Launches a coroutine. Mark long-running coroutines by setting withLoading to loading state.

Parameters

context

additional to CoroutineScope.coroutineContext context of the coroutine.

start

coroutine start option. The default value is CoroutineStart.DEFAULT.

withLoading

Tracks loading state for the (re-)computation. Defaults to ContextualLoading. This should be null for long-running / never-terminating coroutines (e.g. flow.collect).

onError

Optional custom error handler.

block

the coroutine code which will be invoked in the context of the provided scope.