【发布时间】:2018-08-19 10:28:35
【问题描述】:
我反复发现自己是这样编写代码的:
val threadPoolExecutor = Executors.newCachedThreadPool()
val threadPool = threadPool.asCoroutineDispatcher()
我真正需要的只是协程调度器,这样我就可以编写类似的东西
launch(threadPool) { ... }
或
withContext(threadPool) { ... }
我需要threadPoolExecutor 才能在清理时将其关闭。有没有办法使用协程调度程序实例来关闭它?
【问题讨论】: