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
Channel.select bug when closing channel #8231
Comments
Also: ch = Channel(Nil).new
spawn do
loop do
select
when ch.receive
puts "got it"
end
end
end
ch.send nil
ch.close
sleep (it's the same, but please try to use "public" API when reporting these bugs) |
sure, but i don't think |
Yeah, unfortunately it's not documented because the entire concurrency thing is still being revised and implemented. But I just wanted to show that using public API it breaks so it's a legit bug, and not something that you can only cause by using internal API. |
@carlhoerberg In #8243 put some explanation for the alternatives syntax and behavior. If you want to have and "infinite" loop that will exit gracefully (for example upon a Ctrl+C) something like the following might work for you. ch = Channel(Nil).new
exit1 = Channel(Nil).new
exit2 = Channel(Nil).new
Signal::INT.trap do
exit1.send nil
end
spawn do
i = 0
run = true
while run
i = (i + 1) % 1_000
select
when ch.receive
puts "got it"
when exit1.receive
run = false
else
if i == 0
print "."
Fiber.yield
end
end
end
puts "Exiting loop"
exit2.send nil
end
ch.send nil
ch.close
exit2.receive
puts "Bye!" So, the issue in the opening description will still raise an exception in the mentioned PR. Yet, a different one. |
@asterite there needs to be a public API for selecting over dynamically generated groups of fibers. To me |
Yes, but you need to pass a list of channels, not some internal structures. |
The following code:
results in:
The text was updated successfully, but these errors were encountered: