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

Replace try_send/try_recv with is_closed #10138

Closed
brson opened this issue Oct 29, 2013 · 8 comments
Closed

Replace try_send/try_recv with is_closed #10138

brson opened this issue Oct 29, 2013 · 8 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@brson
Copy link
Contributor

brson commented Oct 29, 2013

These methods combine two operations: send/recv and check whether the channel is closed. try_recv in particular does not do what you would expect - recv or return immediately if no message is available.

No expressiveness would be lost by making the is_closed check its own method, though it may be slightly less efficient.

Nominating.

@brson
Copy link
Contributor Author

brson commented Oct 29, 2013

Oh, actually removing try_recv completely means you can't block waiting for a message, then be woken up when the other end closes without sending. There does need to continue to be a try_recv equivalent. It just needs a better name.

@brson
Copy link
Contributor Author

brson commented Oct 29, 2013

Maybe rename try_recv to recv_opt.

@brson
Copy link
Contributor Author

brson commented Oct 29, 2013

try_recv may be an antipattern without actual users. We could try just getting rid of it.

@jdm
Copy link
Contributor

jdm commented Oct 29, 2013

We use it an a number of locations in Servo, fwiw.

@TeXitoi
Copy link
Contributor

TeXitoi commented Oct 29, 2013

I use it for a receiver collecting every messages send by tasks via SharedChan (ie map reduce).

Why not replace actual try_recv() by an implémentation of Iterator::next()?

@nikomatsakis
Copy link
Contributor

It seems like moving to is_closed would introduce a race.

@pnkfelix
Copy link
Member

pnkfelix commented Nov 7, 2013

delegating to @alexcrichton to clean tags post nomination.

@alexcrichton
Copy link
Member

Closing in favor of #10459.

flip1995 pushed a commit to flip1995/rust that referenced this issue Jan 12, 2023
Fix typo in `unused_self` diagnostic message

changelog: Msg: [`unused_self`]: The message now correctly uses *an*
[rust-lang#10138](rust-lang/rust-clippy#10138)
<!-- changelog_checked -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

6 participants