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
25
examples/select.rb
Normal file
25
examples/select.rb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# https://gobyexample.com/select
|
||||
|
||||
require 'channel'
|
||||
|
||||
c1 = Channel.new
|
||||
c2 = Channel.new
|
||||
|
||||
go lambda {
|
||||
sleep(1)
|
||||
c1 << 'one'
|
||||
}
|
||||
|
||||
go lambda {
|
||||
sleep(2)
|
||||
c2 << 'two'
|
||||
}
|
||||
|
||||
2.times do
|
||||
Channel.select(c1, c2) do |msg, c|
|
||||
case c
|
||||
when c1 then puts "received #{msg}"
|
||||
when c2 then puts "received #{msg}"
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue