Skip to content

Fire And Forget Coroutine (ARCH8021)

Key kotlin.async.fire-and-forget-coroutine · Severity warning · Category async

Flags coroutines launched on GlobalScope - unstructured, never cancelled, never joined, their failures invisible.

fun refresh() {
GlobalScope.launch { repository.sync() }
}
class Refresher(private val scope: CoroutineScope) {
fun refresh() = scope.launch { repository.sync() }
}

Launch on an injected CoroutineScope (viewModelScope, lifecycleScope, a supervised app scope) so the job is structured and cancellable.