launched jobs and await can be cancelled while waiting in dispatch queue
* suspendAtomicCancellableCoroutine function is introduced for funs like
send/receive/receiveOrNull that require atomic cancellation
(they cannot be cancelled after decision was made)
* Coroutines started with default mode (CoroutineStart.ATOMIC) using
async/launch/actor builders can be cancelled before execution starts.
* CoroutineStart.ATOMIC is introduced as a start mode to specify that
coroutine cannot be cancelled before its execution start.
diff --git a/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/intrinsics/Undispatched.kt b/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/intrinsics/Undispatched.kt
index e5b18c0..f6cf3b9 100644
--- a/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/intrinsics/Undispatched.kt
+++ b/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/intrinsics/Undispatched.kt
@@ -16,8 +16,11 @@
package kotlinx.coroutines.experimental.intrinsics
+import kotlinx.coroutines.experimental.resumeCancellable
import kotlin.coroutines.experimental.Continuation
-import kotlin.coroutines.experimental.intrinsics.*
+import kotlin.coroutines.experimental.createCoroutine
+import kotlin.coroutines.experimental.intrinsics.COROUTINE_SUSPENDED
+import kotlin.coroutines.experimental.intrinsics.startCoroutineUninterceptedOrReturn
import kotlin.coroutines.experimental.suspendCoroutine
/**
@@ -26,7 +29,7 @@
* @suppress **This is unstable API and it is subject to change.**
*/
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST")
-internal fun <R> (suspend () -> R).startCoroutineUndispatched(completion: Continuation<R>) {
+internal fun <T> (suspend () -> T).startCoroutineUndispatched(completion: Continuation<T>) {
val value = try {
startCoroutineUninterceptedOrReturn(completion)
} catch (e: Throwable) {
@@ -34,7 +37,7 @@
return
}
if (value !== COROUTINE_SUSPENDED)
- completion.resume(value as R)
+ completion.resume(value as T)
}
/**
@@ -43,13 +46,13 @@
* @suppress **This is unstable API and it is subject to change.**
*/
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST")
-internal fun <E, R> (suspend (E) -> R).startCoroutineUndispatched(element: E, completion: Continuation<R>) {
+internal fun <R, T> (suspend (R) -> T).startCoroutineUndispatched(receiver: R, completion: Continuation<T>) {
val value = try {
- startCoroutineUninterceptedOrReturn(element, completion)
+ startCoroutineUninterceptedOrReturn(receiver, completion)
} catch (e: Throwable) {
completion.resumeWithException(e)
return
}
if (value !== COROUTINE_SUSPENDED)
- completion.resume(value as R)
+ completion.resume(value as T)
}