-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Suggestion - Change behavior of select #22
Comments
Hi Michael and thanks for the suggestion. I agree with your points and I think it could be an improvement indeed. Furthermore, I personally don't really like our current naming choices for the cases -- Anyway, we'll have to wait on @rgalanakis for a final position though. |
Thanks for the feedback! |
Based on this example from our test suite: cases = [goless.rcase(self.chan1), goless.dcase()]
result, val = goless.select(cases) I was trying out some ideas inspired by fluent interfaces. Without caring too much to naming, this is what a select statement would look like:
But when writing the tests I realized that the "look-and-feel" that I wanted to achieve (look at the 1st example from the Wikipedia link above) is not practical in Python because of how line-breaks are handled. So I tried using context managers that would allow something like: with goless.buildCases() as b:
b.add_receive(self.chan1)
b.add_default()
cases, result, val = b.select() # or tabbed back, it doesn't matter But this looks too verbose and doesn't look like it improved anything. So I guess our current solution with the addition of the What do you all think? EDIT: Note: I know that I'm abusing/misusing the |
I've created a PR for the new select syntax. |
Okay. @chuim, feel free to alias scase/rcase/dcase if you want. |
Closing this as the main outcome has been address in #23. Add new issues if anyone wants to pursue the other topics. |
I've been playing with the library and I'm enjoying it immensely, but there's one thing that bugs me - why does
select
take a list? Sure, that's the waygo
does it but it's much more Pythonic IMO for it to take an*args
argument.A second point, of which I'm less sure, is that it seems the case used most often for
select
isrcase
, that is, waiting on a result from a channel. I think it would be nice if I could pass a channel object and get it wrapped with anrcase
as a default behavior.So, to recap, I propose:
case, val = goless.select(c1, c2)
Instead of:
case, val = goless.select([goless.rcase(c1), goless.rcase(c2)])
Also, since this would make that switching pattern suggested in the docs less elegant to implement, complementary
is_receive
,is_send
andis_default
methods could be added for testing thecase
return value.If this sounds good to you, I'd be happy to make a pull request with the suggested changes.
The text was updated successfully, but these errors were encountered: