Michael Kotlikov
02/19/2018, 11:04 AMfun newCachedThreadPoolContext() = CachedThreadPoolDispatcher(Executors.newCachedThreadPool())
class CachedThreadPoolDispatcher(private val executor: Executor) : ExecutorCoroutineDispatcherBase() {
override fun dispatch(context: CoroutineContext, block: Runnable) = executor.execute(block)
}
What about this with a static cachedThreadPool?
fun newCachedThreadPoolContext() = CachedThreadPoolDispatcher()
class CachedThreadPoolDispatcher : ExecutorCoroutineDispatcherBase() {
companion object {
private val executor = Executors.newCachedThreadPool()!!
}
override fun dispatch(context: CoroutineContext, block: Runnable) = executor.execute(block)
}