v0ldem0rt
03/28/2019, 2:50 PMExecutorService
to a coroutine dispatcher. How can I do it the other way around i.e. get ExecutorService from disptacherstreetsofboston
03/28/2019, 2:57 PMv0ldem0rt
03/28/2019, 2:59 PMExecutorService
of <http://Dispatchers.IO|Dispatchers.IO>
for example?streetsofboston
03/28/2019, 3:05 PMv0ldem0rt
03/28/2019, 3:08 PMbdawg.io
03/28/2019, 4:43 PMfun CoroutineDispatcher.asExecutor(): Executor = CoroutineScopeExecutor(this)
private class CoroutineScopeExecutor(private val dispatcher: CoroutineDispatcher) : CoroutineScope, Executor {
private val job = SupervisorJob()
override val coroutineContext get() = dispatcher + job
override fun execute(command: Runnable) {
if (!job.isActive) {
throw RejectedExecutionException("Job has been closed")
}
launch {
command.run()
}
}
}