Class: Threaded::Worker
- Inherits:
-
Object
- Object
- Threaded::Worker
- Defined in:
- lib/threaded/worker.rb
Constant Summary collapse
- POISON =
"poison"
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #dead? ⇒ Boolean
-
#initialize(queue, options = {}) ⇒ Worker
constructor
A new instance of Worker.
- #join ⇒ Object
- #poison ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(queue, options = {}) ⇒ Worker
Returns a new instance of Worker.
6 7 8 9 10 |
# File 'lib/threaded/worker.rb', line 6 def initialize(queue, = {}) @queue = queue @logger = [:logger] || Threaded.logger @thread = create_thread end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
4 5 6 |
# File 'lib/threaded/worker.rb', line 4 def logger @logger end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
4 5 6 |
# File 'lib/threaded/worker.rb', line 4 def queue @queue end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
4 5 6 |
# File 'lib/threaded/worker.rb', line 4 def thread @thread end |
Instance Method Details
#alive? ⇒ Boolean
24 25 26 |
# File 'lib/threaded/worker.rb', line 24 def alive? thread.alive? end |
#dead? ⇒ Boolean
20 21 22 |
# File 'lib/threaded/worker.rb', line 20 def dead? !alive? end |
#join ⇒ Object
28 29 30 |
# File 'lib/threaded/worker.rb', line 28 def join thread.join end |
#poison ⇒ Object
12 13 14 |
# File 'lib/threaded/worker.rb', line 12 def poison @queue.enq(POISON) end |
#start ⇒ Object
16 17 18 |
# File 'lib/threaded/worker.rb', line 16 def start puts "start is deprecated, thread is started when worker created" end |