Class: ThreadPool::Executor
- Inherits:
-
Object
- Object
- ThreadPool::Executor
- Includes:
- Loggable
- Defined in:
- lib/thread_pool.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(queue, mutex) ⇒ Executor
constructor
A new instance of Executor.
Constructor Details
#initialize(queue, mutex) ⇒ Executor
Returns a new instance of Executor.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/thread_pool.rb', line 12 def initialize(queue, mutex) @thread = Thread.new do loop do mutex.synchronize { @tuple = queue.shift } if @tuple debug "Executor: processing #{@tuple.hash}" args, block = @tuple @active = true begin block.call(*args) rescue Exception => e error e. error e.backtrace.join("\n") end block.complete = true debug "Executor: complete #{@tuple.hash}" else @active = false sleep 0.01 end end end end |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
10 11 12 |
# File 'lib/thread_pool.rb', line 10 def active @active end |
Instance Method Details
#close ⇒ Object
36 37 38 |
# File 'lib/thread_pool.rb', line 36 def close @thread.exit end |