Class: Swiftcore::Tasks::Task
- Inherits:
-
Object
- Object
- Swiftcore::Tasks::Task
- Includes:
- Comparable
- Defined in:
- lib/swiftcore/tasks/task.rb
Overview
This is a sortable, orderable container for a #call()able object.
Instance Attribute Summary collapse
-
#order ⇒ Object
Returns the value of attribute order.
-
#result ⇒ Object
Returns the value of attribute result.
-
#status ⇒ Object
Returns the value of attribute status.
-
#task ⇒ Object
Returns the value of attribute task.
-
#taskord ⇒ Object
readonly
Returns the value of attribute taskord.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #call(*args) ⇒ Object
- #greater_than(other) ⇒ Object
-
#initialize(order = 0, &task) ⇒ Task
constructor
A new instance of Task.
- #less_than(other) ⇒ Object
Constructor Details
#initialize(order = 0, &task) ⇒ Task
Returns a new instance of Task.
12 13 14 15 16 17 |
# File 'lib/swiftcore/tasks/task.rb', line 12 def initialize(order = 0, &task) @order = order self.task = task @status = :pending @result = nil end |
Instance Attribute Details
#order ⇒ Object
Returns the value of attribute order.
9 10 11 |
# File 'lib/swiftcore/tasks/task.rb', line 9 def order @order end |
#result ⇒ Object
Returns the value of attribute result.
9 10 11 |
# File 'lib/swiftcore/tasks/task.rb', line 9 def result @result end |
#status ⇒ Object
Returns the value of attribute status.
9 10 11 |
# File 'lib/swiftcore/tasks/task.rb', line 9 def status @status end |
#task ⇒ Object
Returns the value of attribute task.
10 11 12 |
# File 'lib/swiftcore/tasks/task.rb', line 10 def task @task end |
#taskord ⇒ Object (readonly)
Returns the value of attribute taskord.
10 11 12 |
# File 'lib/swiftcore/tasks/task.rb', line 10 def taskord @taskord end |
Instance Method Details
#<=>(other) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/swiftcore/tasks/task.rb', line 34 def <=>(other) if less_than(other) -1 elsif greater_than(other) 1 else 0 end end |
#call(*args) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/swiftcore/tasks/task.rb', line 44 def call(*args) @status = :running @result = @task&.call(*args) @status = :finished @result rescue StandardError => e @status = e end |
#greater_than(other) ⇒ Object
29 30 31 32 |
# File 'lib/swiftcore/tasks/task.rb', line 29 def greater_than(other) (@order > other.order) || (@order == other.order && @taskord > other.taskord) end |
#less_than(other) ⇒ Object
24 25 26 27 |
# File 'lib/swiftcore/tasks/task.rb', line 24 def less_than(other) (@order < other.order) || (@order == other.order && @taskord < other.taskord) end |