track

open suspend fun track(withLoading: MutableStateFlow<Int>? = loading, onError: suspend (Throwable) -> Unit? = null, block: suspend () -> Unit)

Tracks a suspension block's loading state and errors.

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

Parameters

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.