Class: Contender::Pool::PoolWorker
- Inherits:
-
Object
- Object
- Contender::Pool::PoolWorker
- Extended by:
- Forwardable
- Defined in:
- lib/contender/pool/pool_worker.rb
Instance Attribute Summary collapse
-
#completed_task_count ⇒ Object
readonly
Returns the value of attribute completed_task_count.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
- #first_task! ⇒ Object
-
#initialize(thread_factory, first_task) ⇒ PoolWorker
constructor
A new instance of PoolWorker.
- #interrupt ⇒ Object
- #on_task_completion ⇒ Object
- #start(&worker_loop) ⇒ Object
Constructor Details
#initialize(thread_factory, first_task) ⇒ PoolWorker
Returns a new instance of PoolWorker.
9 10 11 12 13 14 15 |
# File 'lib/contender/pool/pool_worker.rb', line 9 def initialize(thread_factory, first_task) @mutex = Mutex.new @thread_factory = thread_factory @first_task = first_task @completed_task_count = 0 end |
Instance Attribute Details
#completed_task_count ⇒ Object (readonly)
Returns the value of attribute completed_task_count.
6 7 8 |
# File 'lib/contender/pool/pool_worker.rb', line 6 def completed_task_count @completed_task_count end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
7 8 9 |
# File 'lib/contender/pool/pool_worker.rb', line 7 def thread @thread end |
Instance Method Details
#first_task! ⇒ Object
17 18 19 20 21 |
# File 'lib/contender/pool/pool_worker.rb', line 17 def first_task! @first_task.tap { @first_task = nil } end |
#interrupt ⇒ Object
31 32 33 |
# File 'lib/contender/pool/pool_worker.rb', line 31 def interrupt @thread.raise Interrupt end |
#on_task_completion ⇒ Object
23 24 25 |
# File 'lib/contender/pool/pool_worker.rb', line 23 def on_task_completion @completed_task_count += 1 end |
#start(&worker_loop) ⇒ Object
27 28 29 |
# File 'lib/contender/pool/pool_worker.rb', line 27 def start(&worker_loop) @thread = @thread_factory.create &worker_loop end |