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(parent: (@parent or Task.current), &block) ⇒ Object
- #dequeue ⇒ Object
- #each ⇒ Object
- #enqueue(item) ⇒ Object (also: #<<)
-
#initialize(parent: nil) ⇒ Queue
constructor
A new instance of Queue.
Methods inherited from Notification
Methods inherited from Condition
Constructor Details
#initialize(parent: nil) ⇒ Queue
Returns a new instance of Queue.
26 27 28 29 30 31 |
# File 'lib/async/queue.rb', line 26 def initialize(parent: nil) super() @items = [] @parent = parent end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
33 34 35 |
# File 'lib/async/queue.rb', line 33 def items @items end |
Instance Method Details
#async(parent: (@parent or Task.current), &block) ⇒ Object
51 52 53 54 55 |
# File 'lib/async/queue.rb', line 51 def async(parent: (@parent or Task.current), &block) while item = self.dequeue parent.async(item, &block) end end |
#dequeue ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/async/queue.rb', line 43 def dequeue while @items.empty? self.wait end @items.shift end |
#each ⇒ Object
57 58 59 60 61 |
# File 'lib/async/queue.rb', line 57 def each while item = self.dequeue yield item end end |
#enqueue(item) ⇒ Object Also known as: <<
35 36 37 38 39 |
# File 'lib/async/queue.rb', line 35 def enqueue item @items.push(item) self.signal unless self.empty? end |