Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add
WaitGroup
synchronization primitive #14167Add
WaitGroup
synchronization primitive #14167Changes from 8 commits
fcbc5a0
5e6dee2
c76bc4c
900649a
6564683
720f22e
463c068
8358b01
fe867f4
efdc0bd
8e8756e
8c06bbd
1bb9224
bc7c174
0deae7c
3ecac1c
cd6ae90
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 like this donation very much! It will be very useful in many cases.
One proposal that probably can be done later on as a separate improvement - is to make the
wait
method compatible withselect
to support the following snippet: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.
Or maybe just have
wg.wait(timeout: Time::Span | Nil)
?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.
@bararchy We're missing a generic mechanism for timeouts... but we could abstract how it's implemented for
select
so that could be doable.That doesn't mean we can't also integrate with
select
: we could wait on channel(s) + waitgroup(s) + timeout. Now, I'm not sure how to do that.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.
@ysbaddaden I think that @alexkutsan's idea is better, because then we don't need to handle a Timeout Exception in case that the Timeout happen, and instead handle it in select context which seems cleaner, like how
channel
works when calling "receive" etc..So I think my idea is less clean tbh 😅
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 have a commit to support WaitGroup in
select
expressions.The integration wasn't complex after I understood how SelectAction and SelectContext are working, but the current implementation is very isolated to Channel (on purpose). Maybe the integration is not a good idea, but if proves to be a good idea, we might want to extract the
select
logic fromChannel
to theCrystal
namespace.I'll open a pull request after this one is merged, so we can have a proper discussion.
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.
@ysbaddaden now that it's in and merged, are you planning to make the followup PR? 👁️