https://kotlinlang.org logo
#announcements
Title
# announcements
n

nwh

10/25/2019, 9:47 PM
On the flow page, they use an event stream as an example of a flow use. Is this really a good use case? If you consider a typical event loop, it seems like it should be producing values all the time, regardless of whether or not anything is there to receive them. Isn't that more like a Channel?
g

gildor

10/26/2019, 2:54 PM
Yes it is good use case when you don't want waste resources and close stream if consumer is unsubscribed. It is cold stream
n

nwh

10/26/2019, 6:14 PM
A true event loop is almost never closed (think like a UI application with input events). If you want a listener to be able to receive a subset of events, you wouldn't want to close the stream if it was done listening. For that reason I consider it more to be a hot stream than a cold one: it's always producing values, whether or not someone is listening
g

gildor

10/27/2019, 9:32 AM
Why you don't want to close?
Again, in case of something like view events you of course have events under the hood, but if it exposed as cold stream, stream itself is cold, strat subscription only when someone start observation and finish on unsubscribe
Cold streams have 2 good things comparing to hot: Lazy and safer in terms of resource management (and potentially more efficient)
So nothing wrong to expose even hot source of events as cold stream, it's more universal and safer and opens ways for optimization of source of events (skip processing if there are no listeners)