Replace a couple of usages of suspendCoroutineOrReturn in tests
This commit is contained in:
+13
-6
@@ -8,17 +8,22 @@ import COROUTINES_PACKAGE.*
|
||||
import COROUTINES_PACKAGE.intrinsics.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
suspend fun suspendHere(): String = suspendCoroutineOrReturn { x ->
|
||||
x.resume("OK")
|
||||
COROUTINE_SUSPENDED
|
||||
var callback: () -> Unit = {}
|
||||
|
||||
suspend fun suspendHere(): String = suspendCoroutine { x ->
|
||||
callback = {
|
||||
x.resume("OK")
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun suspendWithException(): String = suspendCoroutineOrReturn { x ->
|
||||
x.resumeWithException(RuntimeException("OK"))
|
||||
COROUTINE_SUSPENDED
|
||||
suspend fun suspendWithException(): String = suspendCoroutine { x ->
|
||||
callback = {
|
||||
x.resumeWithException(RuntimeException("OK"))
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(shouldSuspend: Boolean, expectedCount: Int, c: suspend () -> String): String {
|
||||
callback = {}
|
||||
var fromSuspension: String? = null
|
||||
var counter = 0
|
||||
|
||||
@@ -39,6 +44,8 @@ fun builder(shouldSuspend: Boolean, expectedCount: Int, c: suspend () -> String)
|
||||
"Exception: ${e.message}"
|
||||
}
|
||||
|
||||
callback()
|
||||
|
||||
if (counter != expectedCount) throw RuntimeException("fail 0")
|
||||
|
||||
if (shouldSuspend) {
|
||||
|
||||
@@ -9,19 +9,24 @@ import COROUTINES_PACKAGE.*
|
||||
import COROUTINES_PACKAGE.intrinsics.*
|
||||
|
||||
class Controller {
|
||||
suspend fun suspendHere() = suspendCoroutineOrReturn<String> { x ->
|
||||
x.resume("OK")
|
||||
COROUTINE_SUSPENDED
|
||||
var callback: () -> Unit = {}
|
||||
suspend fun suspendHere() = suspendCoroutine<String> { x ->
|
||||
callback = {
|
||||
x.resume("OK")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(c: suspend Controller.() -> Unit) {
|
||||
c.startCoroutine(Controller(), object : helpers.ContinuationAdapter<Unit>() {
|
||||
val controller = Controller()
|
||||
c.startCoroutine(controller, object : helpers.ContinuationAdapter<Unit>() {
|
||||
override val context: CoroutineContext = EmptyCoroutineContext
|
||||
override fun resume(value: Unit) {}
|
||||
|
||||
override fun resumeWithException(exception: Throwable) {}
|
||||
})
|
||||
|
||||
controller.callback()
|
||||
}
|
||||
|
||||
// FILE: B.kt
|
||||
|
||||
Reference in New Issue
Block a user