mirror of
https://github.com/square/okhttp.git
synced 2025-07-29 17:41:17 +03:00
Reformat with Spotless (#8180)
* Enable spotless * Run spotlessApply * Fixup trimMargin * Re-run spotlessApply
This commit is contained in:
@ -17,23 +17,32 @@
|
||||
|
||||
package okhttp3
|
||||
|
||||
import kotlin.coroutines.resumeWithException
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import okio.IOException
|
||||
import kotlin.coroutines.resumeWithException
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
suspend fun Call.executeAsync(): Response = suspendCancellableCoroutine { continuation ->
|
||||
continuation.invokeOnCancellation {
|
||||
this.cancel()
|
||||
}
|
||||
this.enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
continuation.resumeWithException(e)
|
||||
suspend fun Call.executeAsync(): Response =
|
||||
suspendCancellableCoroutine { continuation ->
|
||||
continuation.invokeOnCancellation {
|
||||
this.cancel()
|
||||
}
|
||||
this.enqueue(
|
||||
object : Callback {
|
||||
override fun onFailure(
|
||||
call: Call,
|
||||
e: IOException,
|
||||
) {
|
||||
continuation.resumeWithException(e)
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
continuation.resume(value = response, onCancellation = { call.cancel() })
|
||||
}
|
||||
})
|
||||
}
|
||||
override fun onResponse(
|
||||
call: Call,
|
||||
response: Response,
|
||||
) {
|
||||
continuation.resume(value = response, onCancellation = { call.cancel() })
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ class SuspendCallTest {
|
||||
MockResponse.Builder()
|
||||
.bodyDelay(5, TimeUnit.SECONDS)
|
||||
.body("abc")
|
||||
.build()
|
||||
.build(),
|
||||
)
|
||||
|
||||
val call = client.newCall(request)
|
||||
@ -109,7 +109,7 @@ class SuspendCallTest {
|
||||
MockResponse.Builder()
|
||||
.bodyDelay(5, TimeUnit.SECONDS)
|
||||
.body("abc")
|
||||
.build()
|
||||
.build(),
|
||||
)
|
||||
|
||||
val call = client.newCall(request)
|
||||
@ -137,7 +137,7 @@ class SuspendCallTest {
|
||||
MockResponse(
|
||||
body = "abc",
|
||||
socketPolicy = DisconnectAfterRequest,
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
val call = client.newCall(request)
|
||||
|
Reference in New Issue
Block a user