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
24
examples/one_to_many.rb
Normal file
24
examples/one_to_many.rb
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# http://stackoverflow.com/questions/15715605/multiple-goroutines-listening-on-one-channel
|
||||
|
||||
require 'channel'
|
||||
require 'channel/waitgroup'
|
||||
|
||||
c = Channel.new
|
||||
w = WaitGroup.new
|
||||
w.add(5)
|
||||
|
||||
1.upto(5) do |i|
|
||||
go(lambda { |i, ci|
|
||||
j = 1
|
||||
ci.each { |v|
|
||||
sleep(0.001)
|
||||
puts format("%d.%d got %d", i, j, v)
|
||||
j += 1
|
||||
}
|
||||
w.done
|
||||
}, i, c)
|
||||
end
|
||||
|
||||
1.upto(25) { |i| c << i }
|
||||
c.close
|
||||
w.wait
|
||||
Loading…
Add table
Add a link
Reference in a new issue