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

crossbeam-channel: Select with priorities? #288

Closed
vorner opened this issue Jan 12, 2019 · 2 comments
Closed

crossbeam-channel: Select with priorities? #288

vorner opened this issue Jan 12, 2019 · 2 comments

Comments

@vorner
Copy link
Contributor

vorner commented Jan 12, 2019

Reading from the docs about the select macro (and the Select type seems to be the same):

This macro allows you to define a set of channel operations, wait until any one of them becomes ready, and finally execute it. If multiple operations are ready at the same time, a random one among them is selected.

I understand this is a good default choice to not starve some operations. However, there are situations when exactly that is desired ‒ I have a higher priority and lower priority channels. In case I can't keep up with everything, I want to prefer handling the higher priority one.

Does it make sense to also have a SelectOrdered or something, that picks the first operation that is ready (in order of insertion) instead of arbitrary one?

@ghost
Copy link

ghost commented Jan 12, 2019

You could achieve the same end result by first polling operations with try_recv()/try_send() in the desired order, and then falling back to select. Maybe not as pretty as using the hypothetical SelectOrdered, but I hope not too bad either?

@vorner
Copy link
Contributor Author

vorner commented Jan 12, 2019

Thanks, how could I miss such an obvious possibility? 😇 Yes, that should work.

@ghost ghost closed this as completed Jan 18, 2019
exrook pushed a commit to exrook/crossbeam that referenced this issue Oct 7, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant