-
-
Save saqib-github-commits/d1e26b9211550d5e42e0167c453063c8 to your computer and use it in GitHub Desktop.
This file contains 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
internal class LaunchedEffectImpl( | |
parentCoroutineContext: CoroutineContext, | |
private val task: suspend CoroutineScope.() -> Unit | |
) : RememberObserver { | |
private val scope = CoroutineScope(parentCoroutineContext) | |
private var job: Job? = null | |
override fun onRemembered() { | |
job?.cancel("Old job was still running!") | |
job = scope.launch(block = task) | |
} | |
override fun onForgotten() { | |
job?.cancel() | |
job = null | |
} | |
override fun onAbandoned() { | |
job?.cancel() | |
job = null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment