tulio
06/21/2019, 4:57 PMstreetsofboston
06/21/2019, 5:01 PMstreetsofboston
06/21/2019, 5:02 PMFlow
‘handles’ back-pressure, by not having any 🙂
When calling emit
in a flow, you can only do that on the scope of the collector, you can’t switch scope, e.g. you can’t do launch { emit(data) }
. If you need to be able to do this, you’d need to create a channelFlow
or callbackFlow
, which introduce a Channel that has back-pressuretulio
06/21/2019, 5:06 PMVsevolod Tolstopyatov [JB]
06/21/2019, 5:12 PMSuspension is a back-pressure in the same manner as‘handles’ back-pressure, by not having any 🙂Flow
Channel()
(with default zero capacity). Flow effectively handles back-pressure, and if you need more than one in-flight element, buffer(n)
can be usedstreetsofboston
06/21/2019, 5:16 PMflow.collect
on the Dispatchers.Main
and the flow itself on <http://Dispatchers.IO|Dispatchers.IO>
, by using flowOn
, the flow effectively got a buffer size > 0…tulio
06/21/2019, 5:27 PMFlow
for cold observables and `Channel`s for hot observables, right?tulio
06/21/2019, 5:27 PMFlow
?streetsofboston
06/21/2019, 5:28 PMcollect
to make a flow ‘active’.streetsofboston
06/21/2019, 5:41 PMcollect
the lambda you provided to flow
, channelFlow
, etc, is called.
The collect
suspends until that lambda has finished.
The flow’s lifecycle and the collector’s lifecycle are tied together like this.
I consider a Flow
to be a special kind of suspend fun
. Whereas a suspend fun
only returns one result in a non-blocking way, a Flow
can ‘return’ a stream of values in a non-blocking way. 🙂