Hi! Is it possible to collect the “StateFlow” in t...
# announcements
v
Hi! Is it possible to collect the “StateFlow” in the same thread as producer? like in RxJava subjects? I’m trying to collect something using StateFlow but I’d like to do it in the producer thread. The collection execution code should block the producer if I do long running operations on the propagated value. The current implementation of flow forces us to use some kind of coroutine launchers for collection. Any help would be appreciated.
c
If you want to implement some kind of event bus, try to implement with SharedFlow, look a this blog, it is very straight forward. https://elizarov.medium.com/shared-flows-broadcast-channels-899b675e805c
e
You can collect in
Dispatchers.Unconfined
. In practice, it will mean collecting in the producer's thread.
v
Thanks @Christopher Elías & @elizarov I’ll check it out.
Dispatchers.Unconfined
works like a charm 🔥
🎉 1