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

Florian

02/06/2021, 12:21 PM
If I call
delay
or any other blocking operation inside the
collect
block of a Flow, the next value will not be collected until that delay is over right? So I can't get race conditions between successive emissions of the Flow?
d

Dominaezzz

02/06/2021, 12:55 PM
Yes, `Flow`s are very strictly sequential.
f

Florian

02/06/2021, 1:03 PM
thank you
p

Paul Woitaschek

02/06/2021, 1:26 PM
Isn't it dependent on the dispatcher?
If you collect on the io dispatcher imo you can get concurrent emissions
d

Dominaezzz

02/06/2021, 1:39 PM
Dispatcher only affects which thread it runs on. The collectors have checks to make sure emission stay sequential (and other nice safe things).
s

streetsofboston

02/06/2021, 2:32 PM
And that ^^^ is one of the main strengths of 'suspend' behavior. Regardless of the dispatcher's number of threads, it guarantees that code can be called sequentially. 😃
3 Views