mirror of
https://github.com/lloeki/normandy.git
synced 2025-12-06 10:04:39 +01:00
WIP
This commit is contained in:
parent
0cdf0a490a
commit
06273c3525
11 changed files with 208 additions and 29 deletions
30
examples/timeouts.rb
Normal file
30
examples/timeouts.rb
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# https://gobyexample.com/timeouts
|
||||
|
||||
require 'channel'
|
||||
require 'channel/timer'
|
||||
|
||||
c1 = Channel.new(1)
|
||||
go lambda {
|
||||
sleep(2)
|
||||
c1 << 'result 1'
|
||||
}
|
||||
|
||||
Channel.select(c1, t1 = Channel::Timer.after(1)) do |res, c|
|
||||
case c
|
||||
when c1 then puts res
|
||||
when t1 then puts 'timeout 1'
|
||||
end
|
||||
end
|
||||
|
||||
c2 = Channel.new(1)
|
||||
go lambda {
|
||||
sleep(2)
|
||||
c2 << 'result 2'
|
||||
}
|
||||
|
||||
Channel.select(c2, t2 = Channel::Timer.after(3)) do |res, c|
|
||||
case c
|
||||
when c2 then puts res
|
||||
when t2 then puts 'timeout 1'
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue