Class: Bixby::ThreadPool::Worker
- Inherits:
-
Object
- Object
- Bixby::ThreadPool::Worker
show all
- Includes:
- Log
- Defined in:
- lib/bixby-common/util/thread_pool/worker.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Log
bin_regex, clean_ex, clean_ex_for_console, console_appender?, gems_regex, #log, ruby_regex, setup_logger
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
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
|