Class: Swiftcore::Tasks::TaskList
- Inherits:
-
SortedSet
- Object
- SortedSet
- Swiftcore::Tasks::TaskList
- Defined in:
- lib/swiftcore/tasks/tasklist.rb
Overview
Just a SortedSet with a few special powers.
Instance Attribute Summary collapse
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #finished? ⇒ Boolean
-
#initialize(*args) ⇒ TaskList
constructor
A new instance of TaskList.
- #run ⇒ Object
-
#tick ⇒ Object
Run a single task in the queue.
Constructor Details
#initialize(*args) ⇒ TaskList
Returns a new instance of TaskList.
12 13 14 15 |
# File 'lib/swiftcore/tasks/tasklist.rb', line 12 def initialize(*args) @status = :pending super(*args) end |
Instance Attribute Details
#status ⇒ Object
Returns the value of attribute status.
10 11 12 |
# File 'lib/swiftcore/tasks/tasklist.rb', line 10 def status @status end |
Instance Method Details
#finished? ⇒ Boolean
23 24 25 26 |
# File 'lib/swiftcore/tasks/tasklist.rb', line 23 def finished? @status = :finished if empty? @status == :finished end |
#run ⇒ Object
17 18 19 20 21 |
# File 'lib/swiftcore/tasks/tasklist.rb', line 17 def run @status = :running tick while any? @status = :finished end |
#tick ⇒ Object
Run a single task in the queue.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/swiftcore/tasks/tasklist.rb', line 29 def tick prior_status = @status @status = :tick task = first result = task.call delete task merge(result) if result.is_a?(TaskList) @status = prior_status finished? result end |