-
-
Save belinwu/5f2cc2d431d4afc4a5063d4f7cd2556d to your computer and use it in GitHub Desktop.
Creates CoroutineScope for Decompose component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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