https://kotlinlang.org logo
Title
t

taer

02/08/2021, 8:19 PM
Is this ok to do?
val pool = Executors.newFixedThreadPool(N)
val dispatcher1 = pool.asCoroutineDispatcher()
val dispatcher2 = pool.asCoroutineDispatcher()
👎 2
🇳🇴 1
The reason is I want 2 different coroutine scopes. One with a pretty nasty CoroutineExceptionHandler and the other normal
I have something like this
class AppCoroutineScope : CoroutineScope by CoroutineScope(dispatcher1 + evilCoroutineExceptionHandler) {
I want this too..
class NiceAppCoroutineScope : CoroutineScope by CoroutineScope(dispatcher2) {e
sharing the same underlying thread pool
z

Zach Klippenstein (he/him) [MOD]

02/08/2021, 9:06 PM
You can use the same dispatcher for those, they’ll still be different scopes
t

taer

02/08/2021, 9:17 PM
Awesome.. I thought so. Thanks for confirmin
z

Zach Klippenstein (he/him) [MOD]

02/08/2021, 9:18 PM
Just to be clear – i would actively avoid creating two dispatchers for this case, since it suggests to readers of your code that they are different somehow and they’re not.
t

taer

02/08/2021, 9:27 PM
Ah.. same dispatcher, varried scopes.
👍 1