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

How to do prioritize select? #7

Closed
siiky opened this issue Mar 26, 2023 · 2 comments
Closed

How to do prioritize select? #7

siiky opened this issue Mar 26, 2023 · 2 comments

Comments

@siiky
Copy link

siiky commented Mar 26, 2023

Hi again :)

I'm trying to use CHICKEN exclusively for a course I'm enrolled in, which is proving to be very interesting and rewarding, but also challenging. In this course we're using Maelstrom to implement and experiment with distributed algorithms and distributed programming, and I hit a limitation with my previous "recipe", in that I have no easy way of implementing timeouts, heartbeats, and the like. Because of that I'm turning now to gochan which is more at-home for me (having a bit of experience with Erlang and Go).

However, I have a problem: let's say I have two channels Ci and Ct (for input and timeout), and that the main thread does a gochan-select on both of them. Would it be possible to somehow prioritize one of the channels over the other (Ct over Ci, specifically)?

Without the "shuffle" mentioned in #6 it's obvious to me how: just order the Ct before the Ci. (In the meantime I'll remove the shuffle from gochan-select*)

@kristianlm
Copy link
Owner

kristianlm commented Mar 27, 2023

Hi siiky,
Thanks for giving gochan a try.

I'm afraid there are no mechanisms for priority in place. Like you discovered, shuffle is hardcoded in.

You can however cheat i bit in some cases, like this:

(gochan-select
  ((pri1 -> msg fail) ...)
  (else 
    (gochan-select
        ((pri1 -> msg fail) ...)
        ((pri2 -> msg fail) ...))))

Where the two bodies of pri1 should be identical. That ensures handling of channel pri1 before pri2 at the start of that snippet.

@siiky
Copy link
Author

siiky commented Mar 30, 2023

Oh of course! I forgot about that trick! Thanks

@siiky siiky closed this as completed Mar 30, 2023
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

No branches or pull requests

2 participants