like this? I feel like im missing something becaus...
# coroutines
m
like this? I feel like im missing something because every call will create a new thread pool. I got some learning left to do.
Copy code
fun 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?
Copy code
fun newCachedThreadPoolContext() = CachedThreadPoolDispatcher()
class CachedThreadPoolDispatcher : ExecutorCoroutineDispatcherBase() {
    companion object {
        private val executor = Executors.newCachedThreadPool()!!
    }
    override fun dispatch(context: CoroutineContext, block: Runnable) = executor.execute(block)
}