Hi guys, anyone explain what is the use of this pe...
# coroutines
k
Hi guys, anyone explain what is the use of this peace of code
Copy code
private val callbackScope = CoroutineScope(Executors.newSingleThreadExecutor().asCoroutineDispatcher())
Thanks
p
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
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
Sure, I'll take a careful about this stuffs. I really appreciate you guys..