-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
Consider implementing a way to try_send without consuming the message #82
Comments
This is already supported! https://docs.rs/flume/0.10.5/flume/struct.Sender.html#method.try_send The function returns a match tx.try_send(foo) {
Ok(()) => /* Successfully sent */,
Err(TrySendError::Full(foo)) | Err(TrySendError::Disconnected(foo)) => /* Failed to send */,
} I could probably make this easier with an |
Um... This is great news! What do you think about Permit API? |
Thinking about this carefully, I think this would be possible to implement: but not without adding some overhead to the crate. I might be able to hide it behind a non-default feature to ensure that most crate users don't need to pay the overhead, however. That said, I'm not sure how this would interact with the For this reason, I'm reluctant to do this at the current time. I'm actually working on a complete implementation overhaul of the crate that might make implementing this significantly easier, however. If I end up implementing this, I'll let you know. |
As a point of interest, the |
I find myself in a situation where I want to try to send a message in a channel and if buffer is full I want to send it to another "overflow" channel
Right now it's impossible to do without wasteful cloning because
try_send
consumes the messageThis can be done either by returning original message in
Result
'sErr
when there was an error or by implementing a similarPermit
API as intokio::sync::mpsc
see https://docs.rs/tokio/1.0.1/tokio/sync/mpsc/struct.Permit.html
I'm personally in favor of
Permit
API as if done right it would allow to do other things, like getting a bunch of Permits(or one bigger Permit, depending on how we implement it) and sending a bunch of messages in one go without waitingIt could probably make sending multiple messages in one go more efficient
On the other hand I could wrap the message into
Arc
this would solve wastefulness of the cloning I doBut the
Permit
API, similar to tokio's could be useful for other things I describedThe text was updated successfully, but these errors were encountered: