-
Notifications
You must be signed in to change notification settings - Fork 16
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
[feature request] re-expose try_recv() #12
Comments
I think my primary question is: why do you want to do a non-blocking Otherwise, I think I'm OK exposing this method since I do feel like you make a reasonably compelling argument. I wish
Yeah, I wonder if |
@BurntSushi I think trying to read all pending messages on a channel without going back into |
That actually sounds a little weird to me. I don't think I've ever had the I don't want to belabor this too much. I am okay with exposing this, but i On Nov 3, 2016 11:49 PM, "James Brown" notifications@github.com wrote:
|
Um, one of the places I use it (which I haven't actually tried to port to |
Incidentally, the code could be simplified a bit if I had a select with timeout (like select(2)/poll(2)/et all). I guess I could emulate that with an extra thread which emits a tick onto a channel periodically, but shrug. There's always another way to write something. James Brown,
|
OK, so this method already exists, but it's not exposed. Here is its signature: fn try_recv(&self) -> Result<Option<T>, ()>; The return type seems a little strange to me. Ideally, it would just return an An enum Try<T> {
Some(T),
WouldBlock,
Closed,
} That seems more explicit to me. |
That seems way better! James Brown,
|
This crate is now deprecated. See: https://users.rust-lang.org/t/ann-chan-is-deprecated-use-crossbeam-channel-instead/19251 |
I'm looking at converting some code from
std::sync::mpsc
tochan
, and the lack oftry_recv
kind of makes my code ugly. For example, consuming all current items on an asynchronous channel without blocking in std looks like the following:In
chan
, this ends up looking likeIf you're in a vaguely-OO context and the receiver is on
self
, this gets even uglier because there are gross contortions required to get a reference to the receiver whose lifetime doesn't spread through the entire method.I appreciate that it's cleaner to just have
select
instead of also having the.try_*
methods, but it seems that it might be more pragmatic to keep both interfaces, especially since it seems like upstream is never going to stabilize Select instd::sync::mpsc
, sochan
is going to be increasingly popular for people who want CSP semantics.The text was updated successfully, but these errors were encountered: