Add CancellationException to all @Throws suspend fun in tests
As this is required by frontend now.
This commit is contained in:
committed by
GitHub
parent
a67cc28a26
commit
23d38bddaa
@@ -6,6 +6,7 @@
|
||||
package coroutines
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.cancellation.CancellationException
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
import kotlin.native.concurrent.isFrozen
|
||||
import kotlin.native.internal.ObjCErrorException
|
||||
@@ -15,7 +16,7 @@ class CoroutineException : Throwable()
|
||||
|
||||
suspend fun suspendFun() = 42
|
||||
|
||||
@Throws(CoroutineException::class)
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
suspend fun suspendFun(result: Any?, doSuspend: Boolean, doThrow: Boolean): Any? {
|
||||
if (doSuspend) {
|
||||
suspendCoroutineUninterceptedOrReturn<Unit> {
|
||||
@@ -41,20 +42,20 @@ class ContinuationHolder<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(CoroutineException::class)
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
suspend fun suspendFunAsync(result: Any?, continuationHolder: ContinuationHolder<Any?>): Any? =
|
||||
suspendCoroutineUninterceptedOrReturn<Any?> {
|
||||
continuationHolder.continuation = it
|
||||
COROUTINE_SUSPENDED
|
||||
} ?: result
|
||||
|
||||
@Throws(CoroutineException::class)
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
fun throwException(exception: Throwable) {
|
||||
throw exception
|
||||
}
|
||||
|
||||
interface SuspendFun {
|
||||
@Throws(CoroutineException::class)
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
suspend fun suspendFun(doYield: Boolean, doThrow: Boolean): Int
|
||||
}
|
||||
|
||||
@@ -84,7 +85,7 @@ fun callSuspendFun(suspendFun: SuspendFun, doYield: Boolean, doThrow: Boolean, r
|
||||
.startCoroutine(ResultHolderCompletion(resultHolder))
|
||||
}
|
||||
|
||||
@Throws(CoroutineException::class)
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
suspend fun callSuspendFun2(suspendFun: SuspendFun, doYield: Boolean, doThrow: Boolean): Int {
|
||||
return suspendFun.suspendFun(doYield = doYield, doThrow = doThrow)
|
||||
}
|
||||
@@ -96,10 +97,10 @@ interface SuspendBridge<T> {
|
||||
suspend fun unit(value: T): Unit
|
||||
suspend fun unitAsAny(value: T): Any?
|
||||
|
||||
@Throws(CoroutineException::class) suspend fun nothing(value: T): Nothing
|
||||
@Throws(CoroutineException::class) suspend fun nothingAsInt(value: T): Int
|
||||
@Throws(CoroutineException::class) suspend fun nothingAsAny(value: T): Any?
|
||||
@Throws(CoroutineException::class) suspend fun nothingAsUnit(value: T): Unit
|
||||
@Throws(Throwable::class) suspend fun nothing(value: T): Nothing
|
||||
@Throws(Throwable::class) suspend fun nothingAsInt(value: T): Int
|
||||
@Throws(Throwable::class) suspend fun nothingAsAny(value: T): Any?
|
||||
@Throws(Throwable::class) suspend fun nothingAsUnit(value: T): Unit
|
||||
}
|
||||
|
||||
abstract class AbstractSuspendBridge : SuspendBridge<Int> {
|
||||
@@ -132,7 +133,7 @@ private suspend fun callAbstractSuspendBridgeImpl(bridge: AbstractSuspendBridge)
|
||||
assertFailsWith<ObjCErrorException> { bridge.nothingAsUnit(10) }
|
||||
}
|
||||
|
||||
@Throws(CoroutineException::class)
|
||||
@Throws(Throwable::class)
|
||||
fun callSuspendBridge(bridge: AbstractSuspendBridge, resultHolder: ResultHolder<Unit>) {
|
||||
suspend {
|
||||
callSuspendBridgeImpl(bridge)
|
||||
|
||||
Reference in New Issue
Block a user