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() { | |
... | |
private fun executeTask(task: Task) { | |
val taskMode = task.mode | |
idleReset(taskMode) | |
beforeTask(taskMode) | |
runSafely(task) | |
afterTask(taskMode) | |
} | |
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() { | |
... | |
while (!isTerminated && state != WorkerState.TERMINATED) { | |
val task = findTask(mayHaveLocalTasks) | |
if (task != null) { | |
... |
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) |
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
@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
@FunctionalInterface | |
public interface Runnable { | |
void run(); | |
} |
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
private inline fun runSafely(completion: Continuation<*>, block: () -> Unit) { | |
try { | |
block() | |
} catch (e: Throwable) { | |
completion.resumeWith(Result.failure(e)) | |
} | |
} |
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
/** | |
* Resumes the execution of the corresponding coroutine passing [value] as the return value of the last suspension point. | |
*/ | |
@SinceKotlin("1.3") | |
@InlineOnly | |
public inline fun <T> Continuation<T>.resume(value: T): Unit = | |
resumeWith(Result.success(value)) | |
/** | |
* Resumes the execution of the corresponding coroutine so that the [exception] is re-thrown right after the |
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 suspend fun delay(timeMillis: Long) { | |
if (timeMillis <= 0) return // don't delay | |
return suspendCancellableCoroutine sc@ { cont: CancellableContinuation<Unit> -> | |
// if timeMillis == Long.MAX_VALUE then just wait forever like awaitCancellation, don't schedule. | |
if (timeMillis < Long.MAX_VALUE) { | |
cont.context.delay.scheduleResumeAfterDelay(timeMillis, cont) | |
} | |
} | |
} |
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
private final Object getRandomNum(Continuation var1) { | |
Object $continuation; | |
label20: { | |
// ... | |
} | |
Object $result = ((<undefinedtype>)$continuation).result; | |
Object var5 = IntrinsicsKt.getCOROUTINE_SUSPENDED(); | |
switch(((<undefinedtype>)$continuation).label) { | |
case 0: |
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
@NotNull | |
public final Continuation create(@Nullable Object value, @NotNull Continuation completion) { | |
Intrinsics.checkNotNullParameter(completion, "completion"); | |
Function2 var3 = new <anonymous constructor>(completion); | |
return var3; | |
} |
NewerOlder