Class: Simrpc::ThreadPoolJobRunner
- Inherits:
-
Object
- Object
- Simrpc::ThreadPoolJobRunner
- Defined in:
- lib/simrpc/thread_pool.rb
Overview
ActiveObject pattern, encapsulate each thread pool thread in object
Instance Attribute Summary collapse
-
#time_started ⇒ Object
Returns the value of attribute time_started.
Instance Method Summary collapse
-
#initialize(thread_pool) ⇒ ThreadPoolJobRunner
constructor
A new instance of ThreadPoolJobRunner.
- #join ⇒ Object
- #run ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(thread_pool) ⇒ ThreadPoolJobRunner
Returns a new instance of ThreadPoolJobRunner.
45 46 47 |
# File 'lib/simrpc/thread_pool.rb', line 45 def initialize(thread_pool) @thread_pool = thread_pool end |
Instance Attribute Details
#time_started ⇒ Object
Returns the value of attribute time_started.
43 44 45 |
# File 'lib/simrpc/thread_pool.rb', line 43 def time_started @time_started end |
Instance Method Details
#join ⇒ Object
65 66 67 |
# File 'lib/simrpc/thread_pool.rb', line 65 def join @thread.join end |
#run ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/simrpc/thread_pool.rb', line 49 def run @thread = Thread.new { until @thread_pool.terminate work = @thread_pool.next_job @time_started = Time.now work.handler.call *work.params unless work.nil? @time_started = nil end } end |
#stop ⇒ Object
60 61 62 63 |
# File 'lib/simrpc/thread_pool.rb', line 60 def stop @thread.kill @thread.join end |