Document that takeWhile can be used as "complete this stream when X comes in"
#23.263 aperta il 30 giu 2017
Metriche repository
- Star
- (13.277 stelle)
- Metriche merge PR
- (Merge medio 8g 19h) (10 PR mergiate in 30 g)
Descrizione
I've found myself needing this many times before, and have needed it on two separate occasions today. When a certain message passes through my flow, I want the flow to complete.
An example use case is a flow for a chat room (implemented using a merge sink), if a leave chat room message passes through the flow, you want to terminate that flow. The sender may not be able to do that, in my specific use case, a user has a single WebSocket connection that multiplexes messages for multiple chat rooms that they may currently be in. The flow is demultiplexed by a broadcast source, filtered for each room, and then sent to merge sinks for each room. The sender of the leave message doesn't want to close the WebSocket after sending the leave chat room message, so can't close the flow, it has to be closed by something in the flow post demux to dynamically remove that flow from the broadcast.