@@ -8,6 +8,13 @@ import kotlinx.coroutines.internal.*
8
8
import kotlin.coroutines.*
9
9
import kotlin.jvm.*
10
10
11
+ @PublishedApi internal const val MODE_ATOMIC_DEFAULT = 0 // schedule non-cancellable dispatch for suspendCoroutine
12
+ @PublishedApi internal const val MODE_CANCELLABLE = 1 // schedule cancellable dispatch for suspendCancellableCoroutine
13
+ @PublishedApi internal const val MODE_UNDISPATCHED = 2 // when the thread is right, but need to mark it with current coroutine
14
+
15
+ internal val Int .isCancellableMode get() = this == MODE_CANCELLABLE
16
+ internal val Int .isDispatchedMode get() = this == MODE_ATOMIC_DEFAULT || this == MODE_CANCELLABLE
17
+
11
18
internal abstract class DispatchedTask <in T >(
12
19
@JvmField public var resumeMode : Int
13
20
) : SchedulerTask() {
@@ -89,7 +96,7 @@ internal abstract class DispatchedTask<in T>(
89
96
}
90
97
}
91
98
92
- internal fun <T > DispatchedTask<T>.dispatch (mode : Int = MODE_CANCELLABLE ) {
99
+ internal fun <T > DispatchedTask<T>.dispatch (mode : Int ) {
93
100
val delegate = this .delegate
94
101
if (mode.isDispatchedMode && delegate is DispatchedContinuation <* > && mode.isCancellableMode == resumeMode.isCancellableMode) {
95
102
// dispatch directly using this instance's Runnable implementation
@@ -125,7 +132,6 @@ internal fun <T> DispatchedTask<T>.resume(delegate: Continuation<T>, useMode: In
125
132
when (useMode) {
126
133
MODE_ATOMIC_DEFAULT -> delegate.resumeWith(result)
127
134
MODE_CANCELLABLE -> delegate.resumeCancellableWith(result)
128
- MODE_DIRECT -> ((delegate as ? DispatchedContinuation )?.continuation ? : delegate).resumeWith(result)
129
135
MODE_UNDISPATCHED -> (delegate as DispatchedContinuation ).resumeUndispatchedWith(result)
130
136
else -> error(" Invalid mode $useMode " )
131
137
}
0 commit comments