Class: Orchestra::ThreadPool::Job

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/orchestra/thread_pool.rb

Constant Summary collapse

Failed =
Module.new

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#blockObject (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

Returns:

  • (Boolean)


126
127
128
# File 'lib/orchestra/thread_pool.rb', line 126

def done?
  not @output_queue.empty?
end

#executeObject



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

#waitObject



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