Class: Orchestra::ThreadPool::Job
- Inherits:
-
Object
- Object
- Orchestra::ThreadPool::Job
- Includes:
- Observable
- Defined in:
- lib/orchestra/thread_pool.rb
Constant Summary collapse
- Failed =
Module.new
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
Instance Method Summary collapse
- #done? ⇒ Boolean
- #execute ⇒ Object
-
#initialize(block) ⇒ Job
constructor
A new instance of Job.
- #set_error(error) ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(block) ⇒ Job
Returns a new instance of Job.
121 122 123 124 |
# File 'lib/orchestra/thread_pool.rb', line 121 def initialize block @block = block @output_queue = Queue.new end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
119 120 121 |
# File 'lib/orchestra/thread_pool.rb', line 119 def block @block end |
Instance Method Details
#done? ⇒ Boolean
126 127 128 |
# File 'lib/orchestra/thread_pool.rb', line 126 def done? not @output_queue.empty? end |
#execute ⇒ Object
130 131 132 |
# File 'lib/orchestra/thread_pool.rb', line 130 def execute @output_queue.push block.call end |
#set_error(error) ⇒ Object
134 135 136 137 |
# File 'lib/orchestra/thread_pool.rb', line 134 def set_error error @error = error @output_queue.push Failed end |
#wait ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/orchestra/thread_pool.rb', line 139 def wait result = @output_queue.pop changed if result == Failed notify_observers :failed, error raise error else notify_observers :finished, result end result end |