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
|
package coroutines
|
||||||
|
|
||||||
import kotlin.coroutines.*
|
import kotlin.coroutines.*
|
||||||
|
import kotlin.coroutines.cancellation.CancellationException
|
||||||
import kotlin.coroutines.intrinsics.*
|
import kotlin.coroutines.intrinsics.*
|
||||||
import kotlin.native.concurrent.isFrozen
|
import kotlin.native.concurrent.isFrozen
|
||||||
import kotlin.native.internal.ObjCErrorException
|
import kotlin.native.internal.ObjCErrorException
|
||||||
@@ -15,7 +16,7 @@ class CoroutineException : Throwable()
|
|||||||
|
|
||||||
suspend fun suspendFun() = 42
|
suspend fun suspendFun() = 42
|
||||||
|
|
||||||
@Throws(CoroutineException::class)
|
@Throws(CoroutineException::class, CancellationException::class)
|
||||||
suspend fun suspendFun(result: Any?, doSuspend: Boolean, doThrow: Boolean): Any? {
|
suspend fun suspendFun(result: Any?, doSuspend: Boolean, doThrow: Boolean): Any? {
|
||||||
if (doSuspend) {
|
if (doSuspend) {
|
||||||
suspendCoroutineUninterceptedOrReturn<Unit> {
|
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? =
|
suspend fun suspendFunAsync(result: Any?, continuationHolder: ContinuationHolder<Any?>): Any? =
|
||||||
suspendCoroutineUninterceptedOrReturn<Any?> {
|
suspendCoroutineUninterceptedOrReturn<Any?> {
|
||||||
continuationHolder.continuation = it
|
continuationHolder.continuation = it
|
||||||
COROUTINE_SUSPENDED
|
COROUTINE_SUSPENDED
|
||||||
} ?: result
|
} ?: result
|
||||||
|
|
||||||
@Throws(CoroutineException::class)
|
@Throws(CoroutineException::class, CancellationException::class)
|
||||||
fun throwException(exception: Throwable) {
|
fun throwException(exception: Throwable) {
|
||||||
throw exception
|
throw exception
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SuspendFun {
|
interface SuspendFun {
|
||||||
@Throws(CoroutineException::class)
|
@Throws(CoroutineException::class, CancellationException::class)
|
||||||
suspend fun suspendFun(doYield: Boolean, doThrow: Boolean): Int
|
suspend fun suspendFun(doYield: Boolean, doThrow: Boolean): Int
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +85,7 @@ fun callSuspendFun(suspendFun: SuspendFun, doYield: Boolean, doThrow: Boolean, r
|
|||||||
.startCoroutine(ResultHolderCompletion(resultHolder))
|
.startCoroutine(ResultHolderCompletion(resultHolder))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(CoroutineException::class)
|
@Throws(CoroutineException::class, CancellationException::class)
|
||||||
suspend fun callSuspendFun2(suspendFun: SuspendFun, doYield: Boolean, doThrow: Boolean): Int {
|
suspend fun callSuspendFun2(suspendFun: SuspendFun, doYield: Boolean, doThrow: Boolean): Int {
|
||||||
return suspendFun.suspendFun(doYield = doYield, doThrow = doThrow)
|
return suspendFun.suspendFun(doYield = doYield, doThrow = doThrow)
|
||||||
}
|
}
|
||||||
@@ -96,10 +97,10 @@ interface SuspendBridge<T> {
|
|||||||
suspend fun unit(value: T): Unit
|
suspend fun unit(value: T): Unit
|
||||||
suspend fun unitAsAny(value: T): Any?
|
suspend fun unitAsAny(value: T): Any?
|
||||||
|
|
||||||
@Throws(CoroutineException::class) suspend fun nothing(value: T): Nothing
|
@Throws(Throwable::class) suspend fun nothing(value: T): Nothing
|
||||||
@Throws(CoroutineException::class) suspend fun nothingAsInt(value: T): Int
|
@Throws(Throwable::class) suspend fun nothingAsInt(value: T): Int
|
||||||
@Throws(CoroutineException::class) suspend fun nothingAsAny(value: T): Any?
|
@Throws(Throwable::class) suspend fun nothingAsAny(value: T): Any?
|
||||||
@Throws(CoroutineException::class) suspend fun nothingAsUnit(value: T): Unit
|
@Throws(Throwable::class) suspend fun nothingAsUnit(value: T): Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class AbstractSuspendBridge : SuspendBridge<Int> {
|
abstract class AbstractSuspendBridge : SuspendBridge<Int> {
|
||||||
@@ -132,7 +133,7 @@ private suspend fun callAbstractSuspendBridgeImpl(bridge: AbstractSuspendBridge)
|
|||||||
assertFailsWith<ObjCErrorException> { bridge.nothingAsUnit(10) }
|
assertFailsWith<ObjCErrorException> { bridge.nothingAsUnit(10) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(CoroutineException::class)
|
@Throws(Throwable::class)
|
||||||
fun callSuspendBridge(bridge: AbstractSuspendBridge, resultHolder: ResultHolder<Unit>) {
|
fun callSuspendBridge(bridge: AbstractSuspendBridge, resultHolder: ResultHolder<Unit>) {
|
||||||
suspend {
|
suspend {
|
||||||
callSuspendBridgeImpl(bridge)
|
callSuspendBridgeImpl(bridge)
|
||||||
|
|||||||
Reference in New Issue
Block a user