https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

deviant

09/07/2017, 11:57 AM
@gildor could you please explain why we need this extra code in each coroutine in the
kotlin-coroutines-retrofit
lib?
Copy code
private fun Call<*>.registerOnCompletion(continuation: CancellableContinuation<*>) {
    continuation.invokeOnCompletion {
        if (continuation.isCancelled)
            try {
                cancel()       // why to cancel already cancelled coroutine?
            } catch (ex: Throwable) {
                //Ignore cancel exception
            }
    }
}
g

gildor

09/07/2017, 12:45 PM
If coroutine is cancelled, then we should cancel retrofit request
d

deviant

09/08/2017, 6:29 AM
yes, thanks. already realized this. initially i thought
cancel
is related to
invokeOnCompletion
lambda 😚
2 Views