This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal abstract class DispatchedTask<in T>( | |
@JvmField public var resumeMode: Int | |
) : SchedulerTask() { | |
...... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@InternalCoroutinesApi | |
public fun <T> Continuation<T>.resumeCancellableWith( | |
result: Result<T>, | |
onCancellation: ((cause: Throwable) -> Unit)? = null | |
): Unit = when (this) { | |
is DispatchedContinuation -> resumeCancellableWith(result, onCancellation) | |
else -> resumeWith(result) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal abstract class DispatchedTask<in T>( | |
@JvmField public var resumeMode: Int | |
) : SchedulerTask() { | |
public final override fun run() { | |
// ... | |
try { | |
val delegate = delegate as DispatchedContinuation<T> | |
val continuation = delegate.continuation | |
withContinuationContext(continuation, delegate.countOrElement) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal inner class Worker private constructor() : Thread() { | |
override fun run() = runWorker() | |
private fun runWorker() { | |
var rescanned = false | |
while (!isTerminated && state != WorkerState.TERMINATED) { | |
val task = findTask(mayHaveLocalTasks) | |
if (task != null) { | |
rescanned = false | |
minDelayUntilStealableTaskNs = 0L | |
executeTask(task) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class CoroutineScheduler( | |
@JvmField val corePoolSize: Int, | |
@JvmField val maxPoolSize: Int, | |
@JvmField val idleWorkerKeepAliveNs: Long = IDLE_WORKER_KEEP_ALIVE_NS, | |
@JvmField val schedulerName: String = DEFAULT_SCHEDULER_NAME | |
) : Executor, Closeable { | |
override fun execute(command: Runnable) = dispatch(command) | |
fun dispatch(block: Runnable, taskContext: TaskContext = NonBlockingContext, tailDispatch: Boolean = false) { | |
trackTask() // this is needed for virtual time support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public actual object Dispatchers { | |
@JvmStatic | |
public actual val Default: CoroutineDispatcher = DefaultScheduler | |
} | |
internal object DefaultScheduler : SchedulerCoroutineDispatcher( | |
CORE_POOL_SIZE, MAX_POOL_SIZE, | |
IDLE_WORKER_KEEP_ALIVE_NS, DEFAULT_SCHEDULER_NAME | |
) { | |
...... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class DispatchedContinuation<in T>( | |
@JvmField val dispatcher: CoroutineDispatcher, | |
@JvmField val continuation: Continuation<T> | |
) : DispatchedTask<T>(MODE_UNINITIALIZED), CoroutineStackFrame, Continuation<T> by continuation { | |
inline fun resumeCancellableWith( | |
result: Result<T>, | |
noinline onCancellation: ((cause: Throwable) -> Unit)? | |
) { | |
val state = result.toState(onCancellation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CoroutineDispatcher | |
public final override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> | |
= DispatchedContinuation(this, continuation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public actual fun <T> Continuation<T>.intercepted(): Continuation<T> = | |
(this as? ContinuationImpl)?.intercepted() ?: this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public fun intercepted(): Continuation<Any?> = | |
intercepted | |
?: (context[ContinuationInterceptor]?.interceptContinuation(this) ?: this) | |
.also { intercepted = it } |