Trying to use a WaitGroup in a select raises the error:
undefined method 'wait_select_action' for WaitGroup
wait_group = WaitGroup.new
select
when wait_group.wait
# ...
when timeout(5.seconds)
raise "timeout :-("
end
The workaround would be to pass a Channel in a Fiber that would call wait and use the channel in the select, and get the feeling that you are doing something that was what WaitGroup was meant to solve.
I agree. It looks good. It’s technically possible, at least in the current implementation (slow). I even have a branch somewhere that implements it.
One issue is that select is completely tied to Channel, with private types that WaitGroup can’t access without exposing them more widely (or moving them under the Crystal namespace).
Another issue is whether it would hinder refactors of select or even Channel to make them more performant (if tied to channel => we can make assumptions).
Last but not least there’s a more general design question: should we disconnect select from Channel? Shall we be able to wait on something else than receiving or sending a message? In Go you can’t for example.