Commit 734c4b81 authored by Geoffrey Métais's avatar Geoffrey Métais

Prevent Exception when coroutine is cancelled

parent cf678dad
......@@ -74,8 +74,10 @@ suspend inline fun <reified T> Context.getFromMl(crossinline block: Medialibrary
else suspendCancellableCoroutine { continuation ->
val listener = object : Medialibrary.OnMedialibraryReadyListener {
override fun onMedialibraryReady() {
continuation.resume(block.invoke(ml))
let { launch { ml.removeOnMedialibraryReadyListener(it) } }
if (!continuation.isCancelled) {
continuation.resume(block.invoke(ml))
let { launch { ml.removeOnMedialibraryReadyListener(it) } }
}
}
override fun onMedialibraryIdle() {}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment