https://kotlinlang.org logo
#coroutines
Title
# coroutines
c

Chris Grigg

04/15/2021, 1:56 PM
Hey everyone, just trying to confirm something here. If I call 
collect
 on a SharedFlow and then call 
delay
 within the collect’s body, will it block other subscribers from retrieving emitted messages? My expectation is that it will because my understanding of flows is that they distribute messages synchronously through subscribers.
So something like this:
Copy code
myFlow.collect { 
  delay(300)
  doSomethingWith(it)
}

// elsewhere
myFlow.collect {
  doSomethingElse(it)
}
Would the 
delay
 in the first 
collect
 have an impact on the second one?
e

ephemient

04/15/2021, 2:42 PM
depends on buffer and replay. I think the default will block emissions until all subscribers have collected, but other than that collectors won't block each other
3 Views