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.
Incorrect
Section titled “Incorrect”fun refresh() { GlobalScope.launch { repository.sync() }}Correct
Section titled “Correct”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.