Skip to content

Instantly share code, notes, and snippets.

@saqib-github-commits
Created May 1, 2023 11:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save saqib-github-commits/d1e26b9211550d5e42e0167c453063c8 to your computer and use it in GitHub Desktop.
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