mirror of
https://github.com/lloeki/normandy.git
synced 2025-12-06 10:04:39 +01:00
examples
This commit is contained in:
parent
1921f98e47
commit
5a968ac76c
11 changed files with 219 additions and 0 deletions
31
examples/closing_channels.rb
Normal file
31
examples/closing_channels.rb
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# https://gobyexample.com/closing-channels
|
||||
|
||||
require 'channel'
|
||||
|
||||
jobs = Channel.new(5)
|
||||
done = Channel.new
|
||||
|
||||
go lambda {
|
||||
loop do
|
||||
begin
|
||||
j = jobs.recv
|
||||
rescue Channel::Closed
|
||||
# TODO: wrong! ends before all items recv'd
|
||||
# j, more := <-jobs; more == True
|
||||
puts 'received all jobs'
|
||||
done << true
|
||||
return
|
||||
else
|
||||
puts "received job #{j}"
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
3.times do |j|
|
||||
jobs << j
|
||||
puts "sent job #{j}"
|
||||
end
|
||||
jobs.close
|
||||
puts 'sent all jobs'
|
||||
|
||||
done.recv
|
||||
Loading…
Add table
Add a link
Reference in a new issue