A default `Flow` isn't closable because it's cold?
# coroutines
r
A default
Flow
isn't closable because it's cold?
s
Correct, a cold flow doesn't do anything except when you collect it, so there would be nothing to "close".
r
Tried making it hot via
shareIn
, apparently I need something different?
s
What are you trying to achieve?
r
I have a flow that's got an end (if the hardware it's represented gets disconnected), and I wanna model that
s
How is the flow created? Is it a regular
flow { ... }
builder or something more complex?
In a flow builder you can end the flow just like you would end regular function invocation, i.e. by throwing an exception, reaching the end of the function, or returning early
r
It's a
channelFlow
, but how do I send something into that scope from the outside? Is there something like an
MVar
in Haskell where I can wait for a single value to be set?
e
CompletableDeferred
is kinda like a one-time
MVar
, but I'm still not clear what you're representing
a flow representing hardware sounds like it should be hot
r
So just make a flow hot somewhere along the chain and it's gonna be hot forever? The hot <-> cold is a bit elusive to me, looks like push/pull based streaming?
e
yes. cold flow = subscribers pull from producers, hot flow = producers push to subscribers. you can make a cold flow hot by starting a coroutine which pulls from the producer and pushes to its subscribers (that's what
.stateIn(scope)
and
.shareIn(scope)
do) but you can't go the other way around