Skip to content

Instantly share code, notes, and snippets.

@aleksandarzekovic
Last active September 15, 2022 20:44
Show Gist options
  • Save aleksandarzekovic/87696b101c99229ea2d8bd925a733ba6 to your computer and use it in GitHub Desktop.
Save aleksandarzekovic/87696b101c99229ea2d8bd925a733ba6 to your computer and use it in GitHub Desktop.
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) {
// ...
val job = if (exception == null && resumeMode.isCancellableMode) context[Job] else null
if (job != null && !job.isActive) {
val cause = job.getCancellationException()
cancelCompletedResult(state, cause)
continuation.resumeWithStackTrace(cause)
} else {
if (exception != null) {
continuation.resumeWithException(exception)
} else {
continuation.resume(getSuccessfulResult(state))
}
}
}
}
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment