Class: Async::Queue
- Inherits:
-
Notification
- Object
- Condition
- Notification
- Async::Queue
- Defined in:
- lib/async/queue.rb
Overview
A queue which allows items to be processed in order.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #async(&block) ⇒ Object
- #dequeue ⇒ Object
- #enqueue(item) ⇒ Object (also: #<<)
-
#initialize ⇒ Queue
constructor
A new instance of Queue.
Methods inherited from Notification
Methods inherited from Condition
Constructor Details
#initialize ⇒ Queue
Returns a new instance of Queue.
26 27 28 29 30 |
# File 'lib/async/queue.rb', line 26 def initialize super @items = [] end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
32 33 34 |
# File 'lib/async/queue.rb', line 32 def items @items end |
Instance Method Details
#async(&block) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/async/queue.rb', line 50 def async(&block) parent = Task.current while item = self.dequeue parent.async(item, &block) end end |
#dequeue ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/async/queue.rb', line 42 def dequeue while @items.empty? self.wait end @items.shift end |
#enqueue(item) ⇒ Object Also known as: <<
34 35 36 37 38 |
# File 'lib/async/queue.rb', line 34 def enqueue item @items.push(item) self.signal unless self.empty? end |