Am I right in thinking that this, which I totally ...
# coroutines
d
Am I right in thinking that this, which I totally didn't write, will permanently tie up one of the few Default threads, and that four of these running on a 4-core machine would prevent any coroutines from running on Default?
Copy code
val someStateFlow: StateFlow<Unit> = ...
GlobalScope.launch(Dispatchers.Default) { someStateFlow.collect { ... } }
"Don't use GlobalScope" yes I know
j
As long as there is no long blocking operation done on the threads, it's not a problem per se. Collecting a stateflow never ends, indeed. But every iteration in the
collect
call has a suspension point, so the thread is regularly yielded to other coroutines (they can interlace freely)
You could technically have concurrency even with 1 thread this way
d
Oh, that makes perfect sense. Thanks (again)
👍 1
j
But yeah, don't use
GlobalScope
😄
d
hahaha I'm trying