-
Notifications
You must be signed in to change notification settings - Fork 8
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 Merge
and MergeNamed
with merge()
#238
Conversation
We already have 2 ways to join multiple receivers, `Merge` and `select`. `MergeNamed` is a mixture of both, so it is redundant. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
This is a more convenient way to use `Merge`, users normally only care about merging some channels, so having a class just makes the syntax more weird for most use cases that will be `async for msg in merge(...)`. `Merge` is not exposed to the user any more. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
This is just to make it more consistent with the internal attribute. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Since `merge()` uses the `_Merge` class, when printing what's returned by `merge()` the string representation of `_Merge` is used. This is not very useful since it doesn't show the name that the user wrote in the code. This commit adds a `name` argument to `_Merge` and uses it to create the string representation of the receiver. If no name is provided, the class name is used as before. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only found a few cosmetics in the documentation to check for, otherwise LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about the late review, just got one comment.
Thanks @llucax, I have no further comments, will approve once you fixup. |
Calling `merge()` with no receivers makes returns a stopped receiver, which can be unexpected if it was done accidentally, as the user will probably expect the merge receiver to block while receiving at least once. By raising an exception we make sure that users express their intentions explicitly instead, having to write something like: ```python receivers: list[Receiver[T]] ... if receivers: async for m in merge(*receivers): ... ``` In this case it is clear the user is having the no-receivers case into account and will handle it properly. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Apply suggestions made by @daniel-zullo-frequenz. Co-authored-by: daniel-zullo-frequenz <120166726+daniel-zullo-frequenz@users.noreply.github.com> Signed-off-by: Leandro Lucarella <luca@llucax.com>
In case `merge()` is called with one receiver there is no need to create a `_Merge` object, we can just return the provided receiver instead. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Just to be consistent to how docstrings are normally written and organized. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
The current tests for merge are really integration tests, as it uses a channel, so we better rename it and mark it as such, as a failure in this test could be actually a failure in `Anycast` instead. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Rebased to apply the fixups and enabled auto-merge. |
MergeNamed
merge()
wrapper function that replacesMerge
Merge
to_Merge
to make it private more explicitly_Merge
variableargs
toreceivers
merge()
is called with less than two receiversFixes #236, fixes #237.