diff --git a/okhttp-coroutines/src/main/kotlin/okhttp3/coroutines/ExecuteAsync.kt b/okhttp-coroutines/src/main/kotlin/okhttp3/coroutines/ExecuteAsync.kt index 07b976a20..c1524e3e0 100644 --- a/okhttp-coroutines/src/main/kotlin/okhttp3/coroutines/ExecuteAsync.kt +++ b/okhttp-coroutines/src/main/kotlin/okhttp3/coroutines/ExecuteAsync.kt @@ -18,7 +18,6 @@ package okhttp3.coroutines import kotlin.coroutines.resumeWithException -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.suspendCancellableCoroutine import okhttp3.Call import okhttp3.Callback @@ -26,7 +25,6 @@ import okhttp3.Response import okhttp3.internal.closeQuietly import okio.IOException -@ExperimentalCoroutinesApi // resume with a resource cleanup. suspend fun Call.executeAsync(): Response = suspendCancellableCoroutine { continuation -> continuation.invokeOnCancellation { @@ -45,8 +43,8 @@ suspend fun Call.executeAsync(): Response = call: Call, response: Response, ) { - continuation.resume(response) { - response.closeQuietly() + continuation.resume(response) { _, value, _ -> + value.closeQuietly() } } }, diff --git a/okhttp-coroutines/src/test/kotlin/okhttp3/coroutines/ExecuteAsyncTest.kt b/okhttp-coroutines/src/test/kotlin/okhttp3/coroutines/ExecuteAsyncTest.kt index 9df5da6c6..bf7c9e75e 100644 --- a/okhttp-coroutines/src/test/kotlin/okhttp3/coroutines/ExecuteAsyncTest.kt +++ b/okhttp-coroutines/src/test/kotlin/okhttp3/coroutines/ExecuteAsyncTest.kt @@ -14,8 +14,6 @@ * limitations under the License. * */ -@file:OptIn(ExperimentalCoroutinesApi::class) - package okhttp3.coroutines import assertk.assertThat @@ -27,7 +25,6 @@ import kotlin.test.assertFailsWith import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.CancellationException import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.TimeoutCancellationException import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.job @@ -93,7 +90,7 @@ class ExecuteAsyncTest { val call = client.newCall(request) - try { + assertFailsWith { withTimeout(1.seconds) { call.executeAsync().use { withContext(Dispatchers.IO) { @@ -102,8 +99,6 @@ class ExecuteAsyncTest { fail("No expected to get response") } } - } catch (to: TimeoutCancellationException) { - // expected } assertThat(call.isCanceled()).isTrue() @@ -123,16 +118,13 @@ class ExecuteAsyncTest { val call = client.newCall(request) - try { + assertFailsWith { call.executeAsync().use { call.cancel() withContext(Dispatchers.IO) { it.body.string() } - fail("No expected to get response") } - } catch (ioe: IOException) { - // expected } assertThat(call.isCanceled()).isTrue() diff --git a/okhttp/src/jvmTest/kotlin/okhttp3/internal/publicsuffix/PublicSuffixListGenerator.kt b/okhttp/src/jvmTest/kotlin/okhttp3/internal/publicsuffix/PublicSuffixListGenerator.kt index 6d507d045..0e0c8e809 100644 --- a/okhttp/src/jvmTest/kotlin/okhttp3/internal/publicsuffix/PublicSuffixListGenerator.kt +++ b/okhttp/src/jvmTest/kotlin/okhttp3/internal/publicsuffix/PublicSuffixListGenerator.kt @@ -13,14 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -@file:OptIn(ExperimentalCoroutinesApi::class) - package okhttp3.internal.publicsuffix import java.util.SortedSet import java.util.TreeSet import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.withContext import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.OkHttpClient