mirror of
https://github.com/lloeki/normandy.git
synced 2025-12-06 01:54:40 +01:00
WIP
This commit is contained in:
parent
0cdf0a490a
commit
06273c3525
11 changed files with 208 additions and 29 deletions
|
|
@ -3,10 +3,13 @@
|
|||
require 'channel'
|
||||
|
||||
def ping(pings, msg)
|
||||
pings = pings.send_only!
|
||||
pings << msg
|
||||
end
|
||||
|
||||
def pong(pings, pongs)
|
||||
pings = pings.receive_only!
|
||||
pongs = pongs.send_only!
|
||||
msg = pings.recv
|
||||
pongs << msg
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
require 'channel'
|
||||
|
||||
def worker(done)
|
||||
puts 'working...'
|
||||
$stdout.write 'working...'
|
||||
sleep 1
|
||||
puts 'done'
|
||||
done << true
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ go lambda {
|
|||
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
|
||||
|
|
@ -21,7 +19,7 @@ go lambda {
|
|||
end
|
||||
}
|
||||
|
||||
3.times do |j|
|
||||
1.upto 3 do |j|
|
||||
jobs << j
|
||||
puts "sent job #{j}"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@ require 'channel'
|
|||
queue = Channel.new(2)
|
||||
queue << 'one'
|
||||
queue << 'two'
|
||||
close(queue)
|
||||
queue.close
|
||||
|
||||
queue.each { |e| puts e }
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# https://gobyexample.com/timeouts
|
||||
|
||||
require 'channel'
|
||||
require 'channel/timeout'
|
||||
require 'channel/timer'
|
||||
|
||||
c1 = Channel.new(1)
|
||||
go lambda {
|
||||
|
|
@ -9,7 +9,7 @@ go lambda {
|
|||
c1 << 'result 1'
|
||||
}
|
||||
|
||||
Channel.select(c1, t1 = Channel::Timeout.after(1)) do |res, c|
|
||||
Channel.select(c1, t1 = Channel::Timer.after(1)) do |res, c|
|
||||
case c
|
||||
when c1 then puts res
|
||||
when t1 then puts 'timeout 1'
|
||||
|
|
@ -22,7 +22,7 @@ go lambda {
|
|||
c2 << 'result 2'
|
||||
}
|
||||
|
||||
Channel.select(c2, t2 = Channel::Timeout.after(3)) do |res, c|
|
||||
Channel.select(c2, t2 = Channel::Timer.after(3)) do |res, c|
|
||||
case c
|
||||
when c2 then puts res
|
||||
when t2 then puts 'timeout 1'
|
||||
Loading…
Add table
Add a link
Reference in a new issue