Class: Bricolage::TaskQueue
- Inherits:
-
Object
- Object
- Bricolage::TaskQueue
- Defined in:
- lib/bricolage/taskqueue.rb
Direct Known Subclasses
Instance Method Summary collapse
- #consume_each ⇒ Object
- #deq ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #enq(task) ⇒ Object
-
#initialize ⇒ TaskQueue
constructor
A new instance of TaskQueue.
- #lock ⇒ Object
- #locked? ⇒ Boolean
- #next ⇒ Object
- #queued? ⇒ Boolean
- #restore ⇒ Object
- #save ⇒ Object
- #size ⇒ Object
- #unlock ⇒ Object
- #unlock_help ⇒ Object
Constructor Details
#initialize ⇒ TaskQueue
Returns a new instance of TaskQueue.
9 10 11 |
# File 'lib/bricolage/taskqueue.rb', line 9 def initialize @queue = [] end |
Instance Method Details
#consume_each ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bricolage/taskqueue.rb', line 29 def consume_each lock save while task = self.next yield task deq end ensure unlock end |
#deq ⇒ Object
48 49 50 51 52 |
# File 'lib/bricolage/taskqueue.rb', line 48 def deq task = @queue.shift save task end |
#each(&block) ⇒ Object
25 26 27 |
# File 'lib/bricolage/taskqueue.rb', line 25 def each(&block) @queue.each(&block) end |
#empty? ⇒ Boolean
13 14 15 |
# File 'lib/bricolage/taskqueue.rb', line 13 def empty? @queue.empty? end |
#enq(task) ⇒ Object
40 41 42 |
# File 'lib/bricolage/taskqueue.rb', line 40 def enq(task) @queue.push task end |
#lock ⇒ Object
64 65 |
# File 'lib/bricolage/taskqueue.rb', line 64 def lock end |
#locked? ⇒ Boolean
60 61 62 |
# File 'lib/bricolage/taskqueue.rb', line 60 def locked? false end |
#next ⇒ Object
44 45 46 |
# File 'lib/bricolage/taskqueue.rb', line 44 def next @queue.first end |
#queued? ⇒ Boolean
21 22 23 |
# File 'lib/bricolage/taskqueue.rb', line 21 def queued? not empty? end |
#restore ⇒ Object
57 58 |
# File 'lib/bricolage/taskqueue.rb', line 57 def restore end |
#save ⇒ Object
54 55 |
# File 'lib/bricolage/taskqueue.rb', line 54 def save end |
#size ⇒ Object
17 18 19 |
# File 'lib/bricolage/taskqueue.rb', line 17 def size @queue.size end |
#unlock ⇒ Object
67 68 |
# File 'lib/bricolage/taskqueue.rb', line 67 def unlock end |
#unlock_help ⇒ Object
70 71 72 |
# File 'lib/bricolage/taskqueue.rb', line 70 def unlock_help "[MUST NOT HAPPEN] this message must not be shown" end |