Skip to content
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

Add a force_send() function to flume::Sender? #142

Open
BTOdell opened this issue Mar 16, 2024 · 0 comments · May be fixed by #143
Open

Add a force_send() function to flume::Sender? #142

BTOdell opened this issue Mar 16, 2024 · 0 comments · May be fixed by #143

Comments

@BTOdell
Copy link

BTOdell commented Mar 16, 2024

Flume has:

  1. flume::Sender::send: block until space is available
  2. flume::Sender::send_async: block until space is available (but async)
  3. flume::Sender::try_send: attempt to send, fail otherwise

I propose adding a new function that implements "lossy ring buffer" functionality:

impl<T> Sender<T> {
    pub fn force_send(&self, value: T) -> Result<Option<T>, SendError<T>> {
        todo!()
    }
}

If the channel is bounded and full, the new value will be forcefully pushed onto the channel and the oldest value that hasn't been received yet will be returned in the Option<T>. If the channel isn't full, then None is returned.

For context, I posted a Reddit thread to ask the community for help/advice for what library to use for this functionality. Although, from my research, it seems like Flume would be a great candidate to directly add this functionality to because it has all of the other features I need! 😄

I'm going to start learning about Flume's code base so I can start formulating a PR.

@BTOdell BTOdell linked a pull request Mar 16, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant