July 2018
Intermediate to advanced
266 pages
7h 11m
English
But there is still one gap. We know that CoroutineDispatcher defines dispatch() to take a CoroutineContext and a Runnable. Here is its signature:
public abstract fun dispatch(context: CoroutineContext, block: Runnable)
So how is it that DispatchedContinuation sends itself as the Runnable, as we just saw? Here is the snippet again:
dispatcher.dispatch(context, this)
As mentioned before, DispatchedContinuation also implements the DispatchedTask interface. This interface extends Runnable by adding a default implementation of run() that can trigger resume() and resumeWithException() in the continuation, as shown here:
public override fun run() { try { val delegate = delegate as DispatchedContinuation<T> val continuation = delegate.continuation ...Read now
Unlock full access