-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to window the fixed-size buffered items in Channel? #1750
Comments
There is no way to do this with a channel, and probably won't be. Flow might get operators to support this behavior, but I don't believe any exist currently. |
There is no "out of the box" solution. I'm curious, though, as to where the need for having such behaviour might arise? How have you encountered this issue? |
@elizarov My situation is just like the back pressure strategy of RxJava.
And I can not find a similar solution by using Channel. Update: after searching around, I think the nearest implementation is like |
Thanks. I know that you can do it in Rx and we are also looking at whether we need to add this kind of a feature to Kotlin flow. For that, we need to know the details. My question if where do you find the need to use it. What is the domain you are working with and what kind of events are you working with? |
@elizarov It's designed for the chat room of live streaming. Sometimes there's a large number of messages sent from websocket, and we'd like the viewers to see the new messages as fresh as possible. Due to the back pressure, we need to control the message buffer size and drop some messages and here we choose to drop the oldest ones. |
When using Channel with capacity > 0, like Channel(3)
I want to keep the buffered item inside the channel as fresh as possible,
The use-case is like following:
I'm looking for a way to let the receiver receives the latest items, e.g.
Is there a way to drop the oldest item in the channel when offer new items to the channel?
The text was updated successfully, but these errors were encountered: