class PWork::Async::Manager
Public Instance Methods
add_task(task)
click to toggle source
This method is called to add a task to the queue
# File lib/pwork/async/manager.rb, line 29 def add_task(task) raise PWork::Async::Exceptions::InvalidOptionsError.new( 'A valid async task must be specified.' ) unless task.is_a?(PWork::Async::Task) task.thread_local_storage = PWork::Helpers::Threads.get_thread_vars process_task(task) end
process_task(task)
click to toggle source
This method is called to process an async task from the queue
# File lib/pwork/async/manager.rb, line 7 def process_task(task) task.thread = Thread.new do task.state = :active thread_helper.set_thread_vars(task.thread_local_storage) begin task.block.call task.state = :complete rescue => e task.error = e task.state = :error ensure thread_helper.reset_thread_vars end end end
thread_helper()
click to toggle source
This method is called to expose the thread helper
# File lib/pwork/async/manager.rb, line 24 def thread_helper PWork::Helpers::Threads end