In the process of migration to Kotlin, the question arose.
We already have some ThreadPools for different reasons.
How to execute coroutine on existed ThreadPool?
For exampe this code :
suspend fun fetchMedia(): Flow<MediaItem> {
return withContext(Dispatchers.IO) {...}
}
How to replace Dispatchers.IO to my own ThreadPoolExecutor ?
You can use Executor ThreadPools calling asCoroutineDispatcher() on it, like this:
suspend fun fetchMedia(): Flow<MediaItem> {
return withContext(myThreadPool.asCoroutineDispatcher()) {...}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With