Hello everybody. I was wondering if there is a way...
# coroutines
e
Hello everybody. I was wondering if there is a way to
emit
values into a
flow
outside its building block. For example sending values when the user clicks a button or if this use-case would be better covered with something else instead of a
Flow
.
s
That is a good example/use-case to use a hot-stream, like a Channel.
And you can create a Flow from a Channel if the consumer needs a Flow
e
In my particular case there might be multiple consumers to the sent messages, but only one emitter, the problem being that this emitters are unknown at the building time of the channel/flow
I will try using a channel for posting the data and converting it into a flow before passing it into the consumers
s
Or a BroadcastChannel may help you out too
e
My first consideration was a BroadcastChannel, but having to specify the buffer size didn't feel right for this usecase (ideally all previous data should be sent to new "subscribers") I will look into ConnectableFlow and keep thinking about this. Thank you
s
The ConnectableFlow is only part of that ‘issue’ (and part of a linked git-gist). It is not part of any ‘official’ coroutines code yet.
e
I see, when I have time I will propose my use-case because it seems that a "ConnectableFlow" is what I need. I create and return the instance of the flow to the potential consumers, then a third service receives the connectableFlow and can emit the values and close it when its coroutine is canceled.
👍 1