Skip to content

Instantly share code, notes, and snippets.

@belinwu
Forked from aartikov/DecomposeUtils.kt
Created November 28, 2023 10:00
Show Gist options
  • Save belinwu/5f2cc2d431d4afc4a5063d4f7cd2556d to your computer and use it in GitHub Desktop.
Save belinwu/5f2cc2d431d4afc4a5063d4f7cd2556d to your computer and use it in GitHub Desktop.
Creates CoroutineScope for Decompose component
fun ComponentContext.componentCoroutineScope(): CoroutineScope {
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
if (lifecycle.state != Lifecycle.State.DESTROYED) {
lifecycle.doOnDestroy {
scope.cancel()
}
} else {
scope.cancel()
}
return scope
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment