Hi guys, anyone explain what is the use of this peace of code
private val callbackScope = CoroutineScope(Executors.newSingleThreadExecutor().asCoroutineDispatcher())
Thanks
p
Patrick Steiger
01/26/2023, 1:44 AM
Having coroutines running on a single thread — can be useful in handling mutable shared state (no need for external synchronization)
If I understand correctly, coroutines cannot run in parallel in that single thread dispatcher configuration
g
gildor
01/26/2023, 2:09 AM
Coroutines can run in parallel, but only one will be in active state at the time (another would suspend)
And careful with it, because it forces only one thread, it’s not so hard to cause deadlock if one coroutines blocks (not suspend) while waiting another one
k
KotlinLeaner
01/26/2023, 9:50 AM
Sure, I'll take a careful about this stuffs. I really appreciate you guys..