Class: Simrpc::ThreadPoolJobRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/simrpc/thread_pool.rb

Overview

ActiveObject pattern, encapsulate each thread pool thread in object

Instance Attribute Summary collapse

Instance Method Summary collapse

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_startedObject

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

#joinObject



65
66
67
# File 'lib/simrpc/thread_pool.rb', line 65

def join
  @thread.join
end

#runObject



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

#stopObject



60
61
62
63
# File 'lib/simrpc/thread_pool.rb', line 60

def stop
  @thread.kill
  @thread.join
end