Class: Garcon::Stash::Queue
Direct Known Subclasses
Instance Method Summary collapse
- #<<(x) ⇒ Object
- #close ⇒ Object
- #first ⇒ Object
- #flush ⇒ Object
-
#initialize ⇒ Queue
constructor
A new instance of Queue.
- #pop ⇒ Object
Constructor Details
#initialize ⇒ Queue
Returns a new instance of Queue.
23 24 25 26 27 28 |
# File 'lib/garcon/stash/queue.rb', line 23 def initialize @queue, @full, @empty = [], [], [] @stop = false @heartbeat = Thread.new(&method(:heartbeat)) @heartbeat.priority = -9 end |
Instance Method Details
#<<(x) ⇒ Object
30 31 32 33 34 |
# File 'lib/garcon/stash/queue.rb', line 30 def <<(x) @queue << x thread = @full.first thread.wakeup if thread end |
#close ⇒ Object
67 68 69 70 |
# File 'lib/garcon/stash/queue.rb', line 67 def close @stop = true @heartbeat.join end |
#first ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# 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 ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# 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 ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/garcon/stash/queue.rb', line 36 def pop @queue.shift if @queue.empty? thread = @empty.first thread.wakeup if thread end end |