July 2018
Intermediate to advanced
266 pages
7h 11m
English
First, it's worth mentioning that isDispatchNeeded() is not overridden in CommonPool, so it will always return true. This guarantees that the dispatch() function is always called when resuming a Continuation, and at this point the Runnable block will be executed using the pool. So let's see the implementation of dispatch() in CommonPool:
override fun dispatch(context: CoroutineContext, block: Runnable) = try { (pool ?: getOrCreatePoolSync()) .execute(timeSource.trackTask(block)) } catch (e: RejectedExecutionException) { timeSource.unTrackTask() DefaultExecutor.execute(block) }
Notice that in the JVM, pool is an instance of java.util.concurrent.Executor, and it's created by either using java.util.concurrent.ForkJoinPool or by ...
Read now
Unlock full access