Skip to content
This repository was archived by the owner on Jun 6, 2019. It is now read-only.

Commit da744e7

Browse files
committed
Cancel the Call if the Deferred is completed by a CancellationException
1 parent d8ad9ca commit da744e7

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/main/java/com/jakewharton/retrofit2/adapter/kotlin/coroutines/CoroutineCallAdapterFactory.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.jakewharton.retrofit2.adapter.kotlin.coroutines
1717

18+
import kotlinx.coroutines.CancellationException
1819
import kotlinx.coroutines.CompletableDeferred
1920
import kotlinx.coroutines.Deferred
2021
import retrofit2.Call
@@ -87,7 +88,7 @@ class CoroutineCallAdapterFactory private constructor() : CallAdapter.Factory()
8788
val deferred = CompletableDeferred<T>()
8889

8990
deferred.invokeOnCompletion {
90-
if (deferred.isCancelled) {
91+
if (deferred.isCancelled && it is CancellationException) {
9192
call.cancel()
9293
}
9394
}

0 commit comments

Comments
 (0)