class Eventbox::ThreadPool::PoolThread
Representation of a work task given as block to ThreadPool.new
Public Instance Methods
__finish__()
click to toggle source
# File lib/eventbox/thread_pool.rb, line 91 def __finish__ @action = nil @joins.each(&:yield) @joins = nil end
__start__(action, input)
click to toggle source
# File lib/eventbox/thread_pool.rb, line 76 def __start__(action, input) # Send the block to the start_pool_thread as result of next_job input.yield(self, @block) # Send all accumulated signals to the action thread @signals.each do |sig| action.raise(*sig) end @action = action @signals = nil @block = nil end
current?()
click to toggle source
# File lib/eventbox/thread_pool.rb, line 54 def current? if a=@action a.current? else false end end
init(block, action)
click to toggle source
# File lib/eventbox/thread_pool.rb, line 32 def init(block, action) @block = block @joins = [] @signals = block ? [] : nil @action = action end
join(result)
click to toggle source
# File lib/eventbox/thread_pool.rb, line 62 def join(result) if j=@joins j << result else # action has already finished result.yield end end
raise(*args)
click to toggle source
# File lib/eventbox/thread_pool.rb, line 39 def raise(*args) # Eventbox::AbortAction would shutdown the thread pool. # To stop the borrowed thread only remap to Eventbox::ThreadPool::AbortAction . args[0] = AbortAction if args[0] == Eventbox::AbortAction if a=@action # The task is running -> send the signal to the thread a.raise(*args) elsif s=@signals # The task is still enqueued -> add the signal to the request s << args end end
terminate()
click to toggle source
# File lib/eventbox/thread_pool.rb, line 71 def terminate @action.abort end