Class: PartTime::Worker
- Inherits:
-
Object
- Object
- PartTime::Worker
- Defined in:
- lib/part_time/worker.rb
Constant Summary collapse
- SHUTDOWN =
"GO HOME!"
Instance Attribute Summary collapse
-
#queue ⇒ Object
Returns the value of attribute queue.
Instance Method Summary collapse
-
#initialize(queue) ⇒ Worker
constructor
A new instance of Worker.
- #join ⇒ Object
- #on_the_clock? ⇒ Boolean
- #work ⇒ Object
Constructor Details
#initialize(queue) ⇒ Worker
Returns a new instance of Worker.
7 8 9 10 11 12 |
# File 'lib/part_time/worker.rb', line 7 def initialize(queue) @queue = queue @on_the_clock = true work end |
Instance Attribute Details
#queue ⇒ Object
Returns the value of attribute queue.
5 6 7 |
# File 'lib/part_time/worker.rb', line 5 def queue @queue end |
Instance Method Details
#join ⇒ Object
26 27 28 |
# File 'lib/part_time/worker.rb', line 26 def join @thread.join end |
#on_the_clock? ⇒ Boolean
30 31 32 |
# File 'lib/part_time/worker.rb', line 30 def on_the_clock? @on_the_clock end |
#work ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/part_time/worker.rb', line 14 def work @thread ||= Thread.new do loop do job, *args = queue.pop break if job == SHUTDOWN job.new.perform(*args) end @on_the_clock = false end end |