From 0f6c50b42b8de428d5196036cd8888091ec65172 Mon Sep 17 00:00:00 2001 From: Andrey Mischenko Date: Sat, 4 Aug 2018 18:43:00 +0800 Subject: [PATCH 1/3] Version 0.12.0-eap13 - stable coroutines (#43) First version of kotlin-coroutines-retrofit based on stable coroutines API from Kotlin 1.3 Compiled against Kotlin 1.3-M1 and kotlinx.coroutines 0.24.0-eap13 (also based on stable API) Migration to SuccessOrFailure --- CHANGELOG.md | 6 +++++ README.md | 8 +++--- build.gradle.kts | 11 +++----- settings.gradle.kts | 12 ++++++++- .../gildor/coroutines/retrofit/CallAwait.kt | 26 +++++++++---------- .../coroutines/retrofit/CallAwaitTest.kt | 10 +++---- 6 files changed, 41 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab8a29c..80b5b00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## Version 0.12.0-eap13 (2017-08-04) - Stable coroutines + +First version of kotlin-coroutines-retrofit based on stable coroutines API from Kotlin 1.3 +Compiled against Kotlin 1.3-M1 and kotlinx.coroutines 0.24.0-eap13 (also based on stable API) + + ## Version 0.12.0 (2017-08-04) - [kotlinx.coroutines 0.24.0](https://github.com/Kotlin/kotlinx.coroutines/releases/tag/0.24.0) diff --git a/README.md b/README.md index 2db28b0..8865958 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,7 @@ This is a small library that provides the [Kotlin Coroutines](https://github.com Based on [kotlinx.coroutines](https://github.com/Kotlin/kotlinx.coroutines) implementation. -This branch uses Kotlin experimental package `kotlin.coroutines.experimental` (pre-1.3). - -Migration to package stable `kotlin.coroutines` package is planned and work in progress. +This branch uses stable version of Kotlin coroutines and work only on Kotlin 1.3 (including EAP builds) ## Download Download the [JAR](https://bintray.com/gildor/maven/kotlin-coroutines-retrofit#files/ru/gildor/coroutines/kotlin-coroutines-retrofit): @@ -18,7 +16,7 @@ Download the [JAR](https://bintray.com/gildor/maven/kotlin-coroutines-retrofit#f Gradle: ```groovy -compile 'ru.gildor.coroutines:kotlin-coroutines-retrofit:0.12.0' +compile 'ru.gildor.coroutines:kotlin-coroutines-retrofit:0.12.0-eap13' ``` Maven:getOrThrow @@ -27,7 +25,7 @@ Maven:getOrThrow ru.gildor.coroutines kotlin-coroutines-retrofit - 0.12.0 + 0.12.0-eap13 ``` diff --git a/build.gradle.kts b/build.gradle.kts index f09f352..690d08a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper plugins { - id("org.jetbrains.kotlin.jvm") version "1.2.60" + id("org.jetbrains.kotlin.jvm") version "1.3-M1" id("com.jfrog.bintray") version "1.8.4" jacoco `maven-publish` @@ -20,11 +20,12 @@ plugins { } group = "ru.gildor.coroutines" -version = "0.12.0" +version = "0.12.0-eap13" description = "Provides Kotlin Coroutines suspendable await() extensions for Retrofit Call" repositories { jcenter() + maven("http://dl.bintray.com/kotlin/kotlin-eap") } java { @@ -34,15 +35,11 @@ java { dependencies { compile("org.jetbrains.kotlin:kotlin-stdlib") - compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.24.0") + compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.24.0-eap13") compile("com.squareup.retrofit2:retrofit:2.4.0") testCompile("junit:junit:4.12") } -kotlin { - experimental.coroutines = Coroutines.ENABLE -} - /* Code coverage */ val jacocoTestReport by tasks.getting(JacocoReport::class) { diff --git a/settings.gradle.kts b/settings.gradle.kts index 572d265..dfa5956 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1 +1,11 @@ -rootProject.name = "kotlin-coroutines-retrofit" \ No newline at end of file +rootProject.name = "kotlin-coroutines-retrofit" + +enableFeaturePreview("STABLE_PUBLISHING") + +pluginManagement { + repositories { + gradlePluginPortal() + jcenter() + maven("http://dl.bintray.com/kotlin/kotlin-eap") + } +} diff --git a/src/main/kotlin/ru/gildor/coroutines/retrofit/CallAwait.kt b/src/main/kotlin/ru/gildor/coroutines/retrofit/CallAwait.kt index 1d9d95b..ddc0c4a 100644 --- a/src/main/kotlin/ru/gildor/coroutines/retrofit/CallAwait.kt +++ b/src/main/kotlin/ru/gildor/coroutines/retrofit/CallAwait.kt @@ -16,12 +16,14 @@ package ru.gildor.coroutines.retrofit -import kotlinx.coroutines.experimental.CancellableContinuation -import kotlinx.coroutines.experimental.suspendCancellableCoroutine +import kotlinx.coroutines.CancellableContinuation +import kotlinx.coroutines.suspendCancellableCoroutine import retrofit2.Call import retrofit2.Callback import retrofit2.HttpException import retrofit2.Response +import kotlin.coroutines.resume +import kotlin.coroutines.resumeWithException /** * Suspend extension that allows suspend [Call] inside of a coroutine. @@ -32,18 +34,14 @@ public suspend fun Call.await(): T { return suspendCancellableCoroutine { continuation -> enqueue(object : Callback { override fun onResponse(call: Call?, response: Response) { - if (response.isSuccessful) { - val body = response.body() - if (body == null) { - continuation.resumeWithException( - NullPointerException("Response body is null: $response") - ) + continuation.resumeWith(SuccessOrFailure.runCatching { + if (response.isSuccessful) { + response.body() + ?: throw NullPointerException("Response body is null: $response") } else { - continuation.resume(body) + throw HttpException(response) } - } else { - continuation.resumeWithException(HttpException(response)) - } + }) } override fun onFailure(call: Call, t: Throwable) { @@ -91,7 +89,7 @@ public suspend fun Call.awaitResult(): Result { return suspendCancellableCoroutine { continuation -> enqueue(object : Callback { override fun onResponse(call: Call?, response: Response) { - continuation.resume( + continuation.resumeWith(SuccessOrFailure.runCatching { if (response.isSuccessful) { val body = response.body() if (body == null) { @@ -102,7 +100,7 @@ public suspend fun Call.awaitResult(): Result { } else { Result.Error(HttpException(response), response.raw()) } - ) + }) } override fun onFailure(call: Call, t: Throwable) { diff --git a/src/test/kotlin/ru/gildor/coroutines/retrofit/CallAwaitTest.kt b/src/test/kotlin/ru/gildor/coroutines/retrofit/CallAwaitTest.kt index ba0015b..b1a801e 100644 --- a/src/test/kotlin/ru/gildor/coroutines/retrofit/CallAwaitTest.kt +++ b/src/test/kotlin/ru/gildor/coroutines/retrofit/CallAwaitTest.kt @@ -16,10 +16,10 @@ package ru.gildor.coroutines.retrofit -import kotlinx.coroutines.experimental.CoroutineScope -import kotlinx.coroutines.experimental.Unconfined -import kotlinx.coroutines.experimental.async -import kotlinx.coroutines.experimental.runBlocking +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Unconfined +import kotlinx.coroutines.async +import kotlinx.coroutines.runBlocking import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNull @@ -32,7 +32,7 @@ import retrofit2.HttpException import ru.gildor.coroutines.retrofit.util.MockedCall import ru.gildor.coroutines.retrofit.util.NullBodyCall import ru.gildor.coroutines.retrofit.util.errorResponse -import kotlin.coroutines.experimental.coroutineContext +import kotlin.coroutines.coroutineContext private const val DONE = "Done!" From f583759e815cd4a0e56a142006ab2d238706fb52 Mon Sep 17 00:00:00 2001 From: Andrey Mischenko Date: Wed, 10 Oct 2018 01:30:07 +0800 Subject: [PATCH 2/3] Version 0.13.0-eap13 with Kotlin 1.3.0-rc-146 --- build.gradle.kts | 6 +++--- src/main/kotlin/ru/gildor/coroutines/retrofit/CallAwait.kt | 4 ++-- .../kotlin/ru/gildor/coroutines/retrofit/CallAwaitTest.kt | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index cd8e192..227d03b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper plugins { - id("org.jetbrains.kotlin.jvm") version "1.3-M1" + id("org.jetbrains.kotlin.jvm") version "1.3.0-rc-146" id("com.jfrog.bintray") version "1.8.4" jacoco `maven-publish` @@ -35,7 +35,7 @@ java { dependencies { compile("org.jetbrains.kotlin:kotlin-stdlib") - compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.24.0-eap13") + compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.30.2-eap13") compile("com.squareup.retrofit2:retrofit:2.4.0") testCompile("junit:junit:4.12") } @@ -78,7 +78,7 @@ val releaseTag = "v${project.version}" val sourcesJar by tasks.creating(Jar::class) { dependsOn("classes") classifier = "sources" - from(sourceSets["main"].allSource) + from(sourceSets["main"].allJava) } val javadocJar by tasks.creating(Jar::class) { diff --git a/src/main/kotlin/ru/gildor/coroutines/retrofit/CallAwait.kt b/src/main/kotlin/ru/gildor/coroutines/retrofit/CallAwait.kt index ddc0c4a..bb0bde7 100644 --- a/src/main/kotlin/ru/gildor/coroutines/retrofit/CallAwait.kt +++ b/src/main/kotlin/ru/gildor/coroutines/retrofit/CallAwait.kt @@ -34,7 +34,7 @@ public suspend fun Call.await(): T { return suspendCancellableCoroutine { continuation -> enqueue(object : Callback { override fun onResponse(call: Call?, response: Response) { - continuation.resumeWith(SuccessOrFailure.runCatching { + continuation.resumeWith(runCatching { if (response.isSuccessful) { response.body() ?: throw NullPointerException("Response body is null: $response") @@ -89,7 +89,7 @@ public suspend fun Call.awaitResult(): Result { return suspendCancellableCoroutine { continuation -> enqueue(object : Callback { override fun onResponse(call: Call?, response: Response) { - continuation.resumeWith(SuccessOrFailure.runCatching { + continuation.resumeWith(runCatching { if (response.isSuccessful) { val body = response.body() if (body == null) { diff --git a/src/test/kotlin/ru/gildor/coroutines/retrofit/CallAwaitTest.kt b/src/test/kotlin/ru/gildor/coroutines/retrofit/CallAwaitTest.kt index b1a801e..2941e6d 100644 --- a/src/test/kotlin/ru/gildor/coroutines/retrofit/CallAwaitTest.kt +++ b/src/test/kotlin/ru/gildor/coroutines/retrofit/CallAwaitTest.kt @@ -17,7 +17,7 @@ package ru.gildor.coroutines.retrofit import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Unconfined +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.runBlocking import org.junit.Assert.assertEquals @@ -32,7 +32,6 @@ import retrofit2.HttpException import ru.gildor.coroutines.retrofit.util.MockedCall import ru.gildor.coroutines.retrofit.util.NullBodyCall import ru.gildor.coroutines.retrofit.util.errorResponse -import kotlin.coroutines.coroutineContext private const val DONE = "Done!" @@ -296,6 +295,6 @@ class CallAwaitTest { } private fun testBlocking(block: suspend CoroutineScope.() -> Unit) { - runBlocking(Unconfined, block) + runBlocking(Dispatchers.Unconfined, block) } From 41473bf38ffacd35b9764e1219576582b7c47712 Mon Sep 17 00:00:00 2001 From: Andrey Mischenko Date: Mon, 5 Nov 2018 07:49:20 +0800 Subject: [PATCH 3/3] Kotlin 1.3 and Kotlinx.Coroutines 1.0 --- CHANGELOG.md | 11 ++- README.md | 31 ++------ build.gradle.kts | 7 +- .../coroutines/retrofit/CallAwaitTest.kt | 75 +++++++++---------- 4 files changed, 54 insertions(+), 70 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcb58c3..e9654f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,21 @@ # CHANGELOG -## Version 0.13.0-eap13 (2017-10-10) +## Version 1.0.0 (2018-11-03) + +- kotlinx.coroutines 1.0.0 +- Compiled against Kotlin 1.3.0 + +## Version 0.13.0-eap13 (2018-10-10) - kotlinx.coroutines 0.30.2-eap13 - Compiled against Kotlin 1.3.0-rc-146 -## Version 0.13.0 (2017-10-10) +## Version 0.13.0 (2018-10-10) - [kotlinx.coroutines 0.30.2](https://github.com/Kotlin/kotlinx.coroutines/releases/tag/0.30.2) - Compiled against Kotlin 1.2.71 -## Version 0.12.0-eap13 (2017-08-04) - Stable coroutines +## Version 0.12.0-eap13 (2018-08-04) - Stable coroutines First version of kotlin-coroutines-retrofit based on stable coroutines API from Kotlin 1.3 Compiled against Kotlin 1.3-M1 and kotlinx.coroutines 0.24.0-eap13 (also based on stable API) diff --git a/README.md b/README.md index 1683bb3..505c60b 100644 --- a/README.md +++ b/README.md @@ -8,46 +8,27 @@ This is a small library that provides the [Kotlin Coroutines](https://github.com Based on [kotlinx.coroutines](https://github.com/Kotlin/kotlinx.coroutines) implementation. -This branch uses stable version of Kotlin coroutines and work only on Kotlin 1.3 (including EAP builds) +New version of library (after 1.0.0) support only Kotlin 1.3 + +Kotlin 1.2 and experimental coroutines are not supported anymore, but you can use version `0.13.0` for old projects. ## Download Download the [JAR](https://bintray.com/gildor/maven/kotlin-coroutines-retrofit#files/ru/gildor/coroutines/kotlin-coroutines-retrofit): -### If you use Kotlin 1.2: Version of the library based on experimental coroutines API - -Gradle: - -```groovy -compile 'ru.gildor.coroutines:kotlin-coroutines-retrofit:0.13.0' -``` - -Maven:getOrThrow - -```xml - - ru.gildor.coroutines - kotlin-coroutines-retrofit - 0.13.0 - -``` - -### If you use Kotlin 1.3: Version based on stable coroutines API - - Gradle: ```groovy -compile 'ru.gildor.coroutines:kotlin-coroutines-retrofit:0.13.0-eap13' +compile 'ru.gildor.coroutines:kotlin-coroutines-retrofit:1.0.0' ``` -Maven:getOrThrow +Maven: ```xml ru.gildor.coroutines kotlin-coroutines-retrofit - 0.13.0-eap13 + 1.0.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 227d03b..46a6a34 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper plugins { - id("org.jetbrains.kotlin.jvm") version "1.3.0-rc-146" + id("org.jetbrains.kotlin.jvm") version "1.3.0" id("com.jfrog.bintray") version "1.8.4" jacoco `maven-publish` @@ -20,12 +20,11 @@ plugins { } group = "ru.gildor.coroutines" -version = "0.13.0-eap13" +version = "1.0.0" description = "Provides Kotlin Coroutines suspendable await() extensions for Retrofit Call" repositories { jcenter() - maven("http://dl.bintray.com/kotlin/kotlin-eap") } java { @@ -35,7 +34,7 @@ java { dependencies { compile("org.jetbrains.kotlin:kotlin-stdlib") - compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.30.2-eap13") + compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0") compile("com.squareup.retrofit2:retrofit:2.4.0") testCompile("junit:junit:4.12") } diff --git a/src/test/kotlin/ru/gildor/coroutines/retrofit/CallAwaitTest.kt b/src/test/kotlin/ru/gildor/coroutines/retrofit/CallAwaitTest.kt index 2941e6d..2ec0a05 100644 --- a/src/test/kotlin/ru/gildor/coroutines/retrofit/CallAwaitTest.kt +++ b/src/test/kotlin/ru/gildor/coroutines/retrofit/CallAwaitTest.kt @@ -16,8 +16,8 @@ package ru.gildor.coroutines.retrofit -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.async import kotlinx.coroutines.runBlocking import org.junit.Assert.assertEquals @@ -35,104 +35,105 @@ import ru.gildor.coroutines.retrofit.util.errorResponse private const val DONE = "Done!" +@ExperimentalCoroutinesApi class CallAwaitTest { @Test - fun asyncSuccess() = testBlocking { + fun asyncSuccess() = runBlocking { assertEquals(DONE, MockedCall(DONE).await()) } @Test(expected = HttpException::class) - fun asyncHttpException() = testBlocking { + fun asyncHttpException() = runBlocking { MockedCall(error = HttpException(errorResponse())).await() } @Test(expected = NullPointerException::class) - fun asyncNullBody() = testBlocking { + fun asyncNullBody() = runBlocking { NullBodyCall().await() } @Test(expected = IllegalArgumentException::class) - fun asyncException() = testBlocking { + fun asyncException() = runBlocking { MockedCall(exception = IllegalArgumentException("wrong get param")).await() } @Test - fun asyncResponseOk() = testBlocking { + fun asyncResponseOk() = runBlocking { val result = MockedCall(DONE).awaitResponse() assertEquals(DONE, result.body()) } @Test - fun asyncResponseError() = testBlocking { + fun asyncResponseError() = runBlocking { val result = MockedCall(error = HttpException(errorResponse(500))).awaitResponse() assertEquals(500, result.code()) } @Test - fun awaitRequestCancel() = testBlocking { + fun awaitRequestCancel() = runBlocking { checkJobCancel { it.await() } } @Test - fun awaitResponseRequestCancel() = testBlocking { + fun awaitResponseRequestCancel() = runBlocking { checkJobCancel { it.awaitResponse() } } @Test - fun awaitResultRequestCancel() = testBlocking { + fun awaitResultRequestCancel() = runBlocking { checkJobCancel { it.awaitResult() } } @Test - fun requestCancelWithException() = testBlocking { + fun requestCancelWithException() = runBlocking { checkRequestCancelWithException { it.awaitResponse() } } @Test - fun awaitRequestCancelWithException() = testBlocking { + fun awaitRequestCancelWithException() = runBlocking { checkRequestCancelWithException { it.await() } } @Test - fun awaitResultCancelWithException() = testBlocking { + fun awaitResultCancelWithException() = runBlocking { checkRequestCancelWithException { it.awaitResult() } } @Test(expected = IllegalArgumentException::class) - fun asyncResponseException() = testBlocking { + fun asyncResponseException() = runBlocking { MockedCall(exception = IllegalArgumentException()).awaitResponse() } @Test - fun awaitJobCancelWithException() = testBlocking { + fun awaitJobCancelWithException() = runBlocking { checkJobCancelWithException { it.await() } } @Test - fun awaitResponseJobCancelWithException() = testBlocking { + fun awaitResponseJobCancelWithException() = runBlocking { checkJobCancelWithException { it.awaitResponse() } } @Test - fun awaitResultJobCancelWithException() = testBlocking { + fun awaitResultJobCancelWithException() = runBlocking { checkJobCancelWithException { it.awaitResult() } } @Test - fun asyncResponseNullBody() = testBlocking { + fun asyncResponseNullBody() = runBlocking { val result = NullBodyCall().awaitResponse() assertNull(result.body()) } @Test - fun asyncResponseNullableBody() = testBlocking { + fun asyncResponseNullableBody() = runBlocking { //Check that we can call awaitResponse() on nullable body val result = NullBodyCall().awaitResponse() assertNull(result.body()) } @Test - fun asyncResponseFailure() = testBlocking { + fun asyncResponseFailure() = runBlocking { val exception = IllegalStateException() try { MockedCall(exception = exception).awaitResult() @@ -142,7 +143,7 @@ class CallAwaitTest { } @Test - fun asyncResultOk() = testBlocking { + fun asyncResultOk() = runBlocking { val result = MockedCall(DONE).awaitResult() when (result) { is Result.Ok -> { @@ -155,19 +156,19 @@ class CallAwaitTest { } @Test - fun asyncResultNullBody() = testBlocking { + fun asyncResultNullBody() = runBlocking { val result = NullBodyCall().awaitResult() assertNull(result.getOrNull()) } @Test(expected = NullPointerException::class) - fun asyncResultNullPointerForNullBody() = testBlocking { + fun asyncResultNullPointerForNullBody() = runBlocking { val result = NullBodyCall().awaitResult() assertNull(result.getOrThrow()) } @Test - fun asyncResultByType() = testBlocking { + fun asyncResultByType() = runBlocking { val result = MockedCall(DONE).awaitResult() when (result) { is ResponseResult -> { @@ -179,7 +180,7 @@ class CallAwaitTest { } @Test - fun resultOkTypes() = testBlocking { + fun resultOkTypes() = runBlocking { val result = MockedCall(DONE).awaitResult() if (result is ResponseResult) { // Mocked raw response doesn't contain body, but we can check code @@ -190,7 +191,7 @@ class CallAwaitTest { } @Test - fun resultErrorTypes() = testBlocking { + fun resultErrorTypes() = runBlocking { val errorResponse = errorResponse(500) val httpException = HttpException(errorResponse) val errorResult = MockedCall(error = httpException).awaitResult() @@ -209,7 +210,7 @@ class CallAwaitTest { } @Test - fun resultExceptionTypes() = testBlocking { + fun resultExceptionTypes() = runBlocking { val exception = IllegalStateException() val errorResult = MockedCall(exception = exception).awaitResult() @@ -222,7 +223,7 @@ class CallAwaitTest { @Test - fun asyncResultError() = testBlocking { + fun asyncResultError() = runBlocking { val error = HttpException(errorResponse(500)) val result = MockedCall(error = error).awaitResult() when (result) { @@ -238,7 +239,7 @@ class CallAwaitTest { } @Test - fun asyncResultException() = testBlocking { + fun asyncResultException() = runBlocking { val exception = IllegalArgumentException("wrong argument") val result = MockedCall(exception = exception).awaitResult() when (result) { @@ -253,13 +254,13 @@ class CallAwaitTest { private fun checkRequestCancelWithException( block: suspend (Call) -> T - ) = testBlocking { + ) = runBlocking { val request = MockedCall( ok = DONE, autoStart = false, cancelException = IllegalStateException() ) - val async = async(coroutineContext, block = { block(request) }) + val async = async(Dispatchers.Unconfined, block = { block(request) }) //We shouldn't crash on cancel exception try { assertFalse(request.isCanceled) @@ -270,12 +271,12 @@ class CallAwaitTest { } } - private fun checkJobCancelWithException(block: suspend (Call) -> T) = testBlocking { + private fun checkJobCancelWithException(block: suspend (Call) -> T) = runBlocking { val request = MockedCall( exception = IllegalArgumentException(), autoStart = false ) - val result = async(coroutineContext) { + val result = async(Dispatchers.Unconfined) { block(request) } result.cancel() @@ -285,16 +286,14 @@ class CallAwaitTest { private fun checkJobCancel( block: suspend (Call) -> T - ) = testBlocking { + ) = runBlocking { val request = MockedCall(DONE, autoStart = false) - val async = async(coroutineContext) { block(request) } + val async = async(Dispatchers.Unconfined) { block(request) } assertFalse(request.isCanceled) async.cancel() assertTrue(request.isCanceled) } -} -private fun testBlocking(block: suspend CoroutineScope.() -> Unit) { - runBlocking(Dispatchers.Unconfined, block) } +