From f3edad2f0b5b867fb39835f904ecd012d0d6983b Mon Sep 17 00:00:00 2001 From: Bradyn Poulsen Date: Mon, 29 Oct 2018 14:09:41 -0600 Subject: [PATCH 1/5] Update to Kotlin 1.3.0 and coroutines 1.0.0 from mavenCentral instead of EAP repositories --- build.gradle | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 0c0f7a8..a58058d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,9 @@ buildscript { repositories { mavenCentral() - maven { url 'http://dl.bintray.com/kotlin/kotlin-eap' } } dependencies { - classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.0-rc-57' + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.0' } } @@ -17,14 +16,12 @@ sourceCompatibility = JavaVersion.VERSION_1_6 repositories { mavenCentral() - maven { url 'http://dl.bintray.com/kotlin/kotlin-eap' } - maven { url 'https://kotlin.bintray.com/kotlinx' } } dependencies { api 'com.squareup.retrofit2:retrofit:2.4.0' - api 'org.jetbrains.kotlin:kotlin-stdlib:1.3.0-rc-57' - api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.26.1-eap13' + api 'org.jetbrains.kotlin:kotlin-stdlib:1.3.0' + api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0' testImplementation 'junit:junit:4.12' testImplementation 'com.squareup.okhttp3:mockwebserver:3.11.0' From 586a9e2b6483b80ffa2f6dd15b6396743480f81f Mon Sep 17 00:00:00 2001 From: Bradyn Poulsen Date: Mon, 29 Oct 2018 14:10:09 -0600 Subject: [PATCH 2/5] Update to 1.0.0-SNAPSHOT --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 540532c..992549d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.jakewharton.retrofit -VERSION_NAME=0.9.3-SNAPSHOT +VERSION_NAME=1.0.0-SNAPSHOT POM_NAME=Retrofit 2 Kotlin Coroutine Adapter POM_DESCRIPTION=A CallAdapter.Factory for Kotlin coroutine's Deferred. From d8ad9cae2f5a10d6182c61c076d6450dc37dea1d Mon Sep 17 00:00:00 2001 From: Bradyn Poulsen Date: Mon, 29 Oct 2018 14:53:16 -0600 Subject: [PATCH 3/5] Migrate CompletableDeferred.isCompletedExceptionally to its deprecation change in coroutines 0.27.0+ --- .../retrofit2/adapter/kotlin/coroutines/CancelTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/jakewharton/retrofit2/adapter/kotlin/coroutines/CancelTest.kt b/src/test/java/com/jakewharton/retrofit2/adapter/kotlin/coroutines/CancelTest.kt index d7ae298..b99b761 100644 --- a/src/test/java/com/jakewharton/retrofit2/adapter/kotlin/coroutines/CancelTest.kt +++ b/src/test/java/com/jakewharton/retrofit2/adapter/kotlin/coroutines/CancelTest.kt @@ -36,7 +36,7 @@ class CancelTest { val deferred = adapter.adapt(call) call.completeWithException(IOException()) assertFalse(call.isCanceled) - assertTrue(deferred.isCompletedExceptionally) + assertTrue(deferred.isCancelled && deferred.isCompleted) } @Test fun cancelOnCancel() { From 4b32e53ee1584f8c0fc20455e868df2df7c150c2 Mon Sep 17 00:00:00 2001 From: Bradyn Poulsen Date: Mon, 29 Oct 2018 16:15:37 -0600 Subject: [PATCH 4/5] Cancel the Call if the Deferred is completed by a CancellationException --- .../coroutines/CoroutineCallAdapterFactory.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/jakewharton/retrofit2/adapter/kotlin/coroutines/CoroutineCallAdapterFactory.kt b/src/main/java/com/jakewharton/retrofit2/adapter/kotlin/coroutines/CoroutineCallAdapterFactory.kt index 60771e6..06c0b9a 100644 --- a/src/main/java/com/jakewharton/retrofit2/adapter/kotlin/coroutines/CoroutineCallAdapterFactory.kt +++ b/src/main/java/com/jakewharton/retrofit2/adapter/kotlin/coroutines/CoroutineCallAdapterFactory.kt @@ -15,6 +15,7 @@ */ package com.jakewharton.retrofit2.adapter.kotlin.coroutines +import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.Deferred import retrofit2.Call @@ -87,7 +88,12 @@ class CoroutineCallAdapterFactory private constructor() : CallAdapter.Factory() val deferred = CompletableDeferred() deferred.invokeOnCompletion { - if (deferred.isCancelled) { + /** + * The [call] should not be marked as cancelled when it completes exceptionally. + * If the cause of cancellation is [CancellationException], then the [CompletableDeferred] is + * considered to be _cancelled normally_. + */ + if (deferred.isCancelled && it is CancellationException) { call.cancel() } } @@ -120,7 +126,12 @@ class CoroutineCallAdapterFactory private constructor() : CallAdapter.Factory() val deferred = CompletableDeferred>() deferred.invokeOnCompletion { - if (deferred.isCancelled) { + /** + * The [call] should not be marked as cancelled when it completes exceptionally. + * If the cause of cancellation is [CancellationException], then the [CompletableDeferred] is + * considered to be _cancelled normally_. + */ + if (deferred.isCancelled && it is CancellationException) { call.cancel() } } From 275fa3755eac995003dc423c827b3264ccb4551b Mon Sep 17 00:00:00 2001 From: Bradyn Poulsen Date: Wed, 19 Dec 2018 12:13:30 -0700 Subject: [PATCH 5/5] Update to Kotlin 1.3.11 and coroutines 1.0.1 --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index a58058d..62ab6a0 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.0' + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.11' } } @@ -20,8 +20,8 @@ repositories { dependencies { api 'com.squareup.retrofit2:retrofit:2.4.0' - api 'org.jetbrains.kotlin:kotlin-stdlib:1.3.0' - api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0' + api 'org.jetbrains.kotlin:kotlin-stdlib:1.3.11' + api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.1' testImplementation 'junit:junit:4.12' testImplementation 'com.squareup.okhttp3:mockwebserver:3.11.0'