Class: Bixby::ThreadPool::Worker
- Inherits:
-
Object
- Object
- Bixby::ThreadPool::Worker
- Includes:
- Log
- Defined in:
- lib/bixby-common/util/thread_pool/worker.rb
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(queue, idle_timeout, exit_handler) ⇒ Worker
constructor
A new instance of Worker.
- #inspect ⇒ Object
- #join(max_wait = nil) ⇒ Object
- #to_s ⇒ Object
- #working? ⇒ Boolean
Methods included from Log
Constructor Details
#initialize(queue, idle_timeout, exit_handler) ⇒ Worker
Returns a new instance of Worker.
12 13 14 15 16 17 18 19 |
# File 'lib/bixby-common/util/thread_pool/worker.rb', line 12 def initialize(queue, idle_timeout, exit_handler) @input_queue = queue @idle_timeout = idle_timeout @exit_handler = exit_handler @running = true @working = false @thread = Thread.new { start_run_loop } end |
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
10 11 12 |
# File 'lib/bixby-common/util/thread_pool/worker.rb', line 10 def thread @thread end |
Instance Method Details
#alive? ⇒ Boolean
29 30 31 |
# File 'lib/bixby-common/util/thread_pool/worker.rb', line 29 def alive? return @running && @thread && @thread.alive? end |
#inspect ⇒ Object
37 38 39 |
# File 'lib/bixby-common/util/thread_pool/worker.rb', line 37 def inspect return "#<#{self.class.to_s}:0x#{(object_id << 1).to_s(16)} #{alive? ? 'alive' : 'dead'}>" end |
#join(max_wait = nil) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/bixby-common/util/thread_pool/worker.rb', line 21 def join(max_wait = nil) raise "Worker can't join itself." if @thread == Thread.current return true if @thread.nil? || !@thread.join(max_wait).nil? @thread.kill and return false end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/bixby-common/util/thread_pool/worker.rb', line 41 def to_s inspect end |
#working? ⇒ Boolean
33 34 35 |
# File 'lib/bixby-common/util/thread_pool/worker.rb', line 33 def working? @working end |