Class: Philiprehberger::TaskQueue::Worker
- Inherits:
-
Object
- Object
- Philiprehberger::TaskQueue::Worker
- Defined in:
- lib/philiprehberger/task_queue/worker.rb
Overview
Worker processes tasks from the queue in a dedicated thread.
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
-
#alive? ⇒ Boolean
Whether the underlying worker thread is still alive.
-
#initialize(queue, mutex, condition, context:) ⇒ Worker
constructor
A new instance of Worker.
-
#stop ⇒ void
Signal the worker to stop after its current task completes.
Constructor Details
#initialize(queue, mutex, condition, context:) ⇒ Worker
Returns a new instance of Worker.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/philiprehberger/task_queue/worker.rb', line 9 def initialize(queue, mutex, condition, context:) @queue = queue @mutex = mutex @condition = condition @stats = context[:stats] @error_handler = context[:error_handler] @complete_handler = context[:complete_handler] @drain_condition = context[:drain_condition] @paused = context[:paused] @pause_condition = context[:pause_condition] @running = true @thread = Thread.new { run } end |
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
7 8 9 |
# File 'lib/philiprehberger/task_queue/worker.rb', line 7 def thread @thread end |
Instance Method Details
#alive? ⇒ Boolean
Whether the underlying worker thread is still alive.
34 35 36 |
# File 'lib/philiprehberger/task_queue/worker.rb', line 34 def alive? @thread&.alive? || false end |
#stop ⇒ void
This method returns an undefined value.
Signal the worker to stop after its current task completes.
26 27 28 29 |
# File 'lib/philiprehberger/task_queue/worker.rb', line 26 def stop @running = false nil end |