TaskScope

interface TaskScope

Registry of keyed coroutine tasks scoped to a parent CoroutineScope.

Use one instance per lifecycle owner (ViewModel via taskScope(), Composable via rememberTaskScope()).

Implementations must treat Idle/Running resets as identity-guarded: when a job completes, the key returns to TaskJobState.Idle only if that same Job instance is still registered. Concurrent launch/cancel/ and completion callbacks are safe from any thread.

Functions

Link copied to clipboard
abstract fun cancel(key: TaskKey)
Link copied to clipboard
abstract fun cancelAll()
Link copied to clipboard
abstract fun isActive(key: TaskKey): Boolean
Link copied to clipboard
abstract fun launch(key: TaskKey, policy: TaskPolicy = TaskPolicy.SkipIfActive, block: suspend CoroutineScope.() -> Unit): TaskLaunchResult
Link copied to clipboard
fun TaskScope.taskState(key: TaskKey): StateFlow<TaskJobState>