1
0
mirror of https://github.com/square/okhttp.git synced 2025-07-29 17:41:17 +03:00

Stop using experimental coroutines APIs (#8867)

They're stable now.

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
This commit is contained in:
Jesse Wilson
2025-06-19 00:20:30 -04:00
committed by GitHub
parent dd70d9e579
commit 570277976d
3 changed files with 4 additions and 17 deletions

View File

@ -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()
}
}
},

View File

@ -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<TimeoutCancellationException> {
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<IOException> {
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()