class Garcon::Stash::Queue
Public Class Methods
new()
click to toggle source
# File lib/garcon/stash/queue.rb, line 23 def initialize @queue, @full, @empty = [], [], [] @stop = false @heartbeat = Thread.new(&method(:heartbeat)) @heartbeat.priority = -9 end
Public Instance Methods
<<(x)
click to toggle source
# File lib/garcon/stash/queue.rb, line 30 def <<(x) @queue << x thread = @full.first thread.wakeup if thread end
close()
click to toggle source
# File lib/garcon/stash/queue.rb, line 67 def close @stop = true @heartbeat.join end
first()
click to toggle source
# File lib/garcon/stash/queue.rb, line 44 def first while @queue.empty? begin @full << Thread.current Thread.stop while @queue.empty? ensure @full.delete(Thread.current) end end @queue.first end
flush()
click to toggle source
# File lib/garcon/stash/queue.rb, line 56 def flush until @queue.empty? begin @empty << Thread.current Thread.stop until @queue.empty? ensure @empty.delete(Thread.current) end end end
pop()
click to toggle source
# File lib/garcon/stash/queue.rb, line 36 def pop @queue.shift if @queue.empty? thread = @empty.first thread.wakeup if thread end end