mirror of
https://github.com/square/okhttp.git
synced 2025-07-31 05:04:26 +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:
@ -18,7 +18,6 @@
|
|||||||
package okhttp3.coroutines
|
package okhttp3.coroutines
|
||||||
|
|
||||||
import kotlin.coroutines.resumeWithException
|
import kotlin.coroutines.resumeWithException
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
import okhttp3.Call
|
import okhttp3.Call
|
||||||
import okhttp3.Callback
|
import okhttp3.Callback
|
||||||
@ -26,7 +25,6 @@ import okhttp3.Response
|
|||||||
import okhttp3.internal.closeQuietly
|
import okhttp3.internal.closeQuietly
|
||||||
import okio.IOException
|
import okio.IOException
|
||||||
|
|
||||||
@ExperimentalCoroutinesApi // resume with a resource cleanup.
|
|
||||||
suspend fun Call.executeAsync(): Response =
|
suspend fun Call.executeAsync(): Response =
|
||||||
suspendCancellableCoroutine { continuation ->
|
suspendCancellableCoroutine { continuation ->
|
||||||
continuation.invokeOnCancellation {
|
continuation.invokeOnCancellation {
|
||||||
@ -45,8 +43,8 @@ suspend fun Call.executeAsync(): Response =
|
|||||||
call: Call,
|
call: Call,
|
||||||
response: Response,
|
response: Response,
|
||||||
) {
|
) {
|
||||||
continuation.resume(response) {
|
continuation.resume(response) { _, value, _ ->
|
||||||
response.closeQuietly()
|
value.closeQuietly()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@file:OptIn(ExperimentalCoroutinesApi::class)
|
|
||||||
|
|
||||||
package okhttp3.coroutines
|
package okhttp3.coroutines
|
||||||
|
|
||||||
import assertk.assertThat
|
import assertk.assertThat
|
||||||
@ -27,7 +25,6 @@ import kotlin.test.assertFailsWith
|
|||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
||||||
import kotlinx.coroutines.TimeoutCancellationException
|
import kotlinx.coroutines.TimeoutCancellationException
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.coroutines.job
|
import kotlinx.coroutines.job
|
||||||
@ -93,7 +90,7 @@ class ExecuteAsyncTest {
|
|||||||
|
|
||||||
val call = client.newCall(request)
|
val call = client.newCall(request)
|
||||||
|
|
||||||
try {
|
assertFailsWith<TimeoutCancellationException> {
|
||||||
withTimeout(1.seconds) {
|
withTimeout(1.seconds) {
|
||||||
call.executeAsync().use {
|
call.executeAsync().use {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
@ -102,8 +99,6 @@ class ExecuteAsyncTest {
|
|||||||
fail("No expected to get response")
|
fail("No expected to get response")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (to: TimeoutCancellationException) {
|
|
||||||
// expected
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat(call.isCanceled()).isTrue()
|
assertThat(call.isCanceled()).isTrue()
|
||||||
@ -123,16 +118,13 @@ class ExecuteAsyncTest {
|
|||||||
|
|
||||||
val call = client.newCall(request)
|
val call = client.newCall(request)
|
||||||
|
|
||||||
try {
|
assertFailsWith<IOException> {
|
||||||
call.executeAsync().use {
|
call.executeAsync().use {
|
||||||
call.cancel()
|
call.cancel()
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
it.body.string()
|
it.body.string()
|
||||||
}
|
}
|
||||||
fail("No expected to get response")
|
|
||||||
}
|
}
|
||||||
} catch (ioe: IOException) {
|
|
||||||
// expected
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat(call.isCanceled()).isTrue()
|
assertThat(call.isCanceled()).isTrue()
|
||||||
|
@ -13,14 +13,11 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
@file:OptIn(ExperimentalCoroutinesApi::class)
|
|
||||||
|
|
||||||
package okhttp3.internal.publicsuffix
|
package okhttp3.internal.publicsuffix
|
||||||
|
|
||||||
import java.util.SortedSet
|
import java.util.SortedSet
|
||||||
import java.util.TreeSet
|
import java.util.TreeSet
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
|
Reference in New Issue
Block a user