function?
I want to cancel my listener when my coroutine is no longer active. I don’t have access to the scope, but I can use
currentCoroutineContext()
since i’m inside a suspend function. Could this have any negative impact? Like memory leak or a false-positive?
Copy code
private suspend fun doEffects(colorChangeCallback: OnColorChangedCallback, valueAnimator: ValueAnimator) {
val context: CoroutineContext = currentCoroutineContext()
valueAnimator.addUpdateListener {
if (context.isActive) {
// Do your work
} else {
// Cancel other work
valueAnimator.cancel()
}
}
}