Class: Contender::Pool::PoolWorker
- Inherits:
-
Object
- Object
- Contender::Pool::PoolWorker
- Defined in:
- lib/contender/pool/pool_worker.rb
Overview
Encapsulates a single worker thread in a thread pool
Instance Method Summary collapse
-
#executing? ⇒ Boolean
Returns true if the pool worker is executing a task.
-
#inactive? ⇒ Boolean
Returns true if the pool worker is inactive.
- #initialize(pool, queue, non_block = false) ⇒ undefined constructor
- #interrupt ⇒ undefined
- #join ⇒ undefined
- #start ⇒ undefined
-
#waiting? ⇒ Boolean
Returns true if the pool worker is waiting for tasks.
Constructor Details
#initialize(pool, queue, non_block = false) ⇒ undefined
9 10 11 12 13 14 15 16 |
# File 'lib/contender/pool/pool_worker.rb', line 9 def initialize(pool, queue, non_block = false) @pool = pool @queue = queue @non_block = non_block # Only changed in the worker thread @state = :inactive end |
Instance Method Details
#executing? ⇒ Boolean
Returns true if the pool worker is executing a task
53 54 55 |
# File 'lib/contender/pool/pool_worker.rb', line 53 def executing? :executing == @state end |
#inactive? ⇒ Boolean
Returns true if the pool worker is inactive
41 42 43 |
# File 'lib/contender/pool/pool_worker.rb', line 41 def inactive? :inactive == @state end |
#interrupt ⇒ undefined
34 35 36 37 |
# File 'lib/contender/pool/pool_worker.rb', line 34 def interrupt return unless @thread @thread.raise OperationInterrupted end |
#join ⇒ undefined
28 29 30 31 |
# File 'lib/contender/pool/pool_worker.rb', line 28 def join return unless @thread @thread.join end |
#start ⇒ undefined
19 20 21 22 23 24 25 |
# File 'lib/contender/pool/pool_worker.rb', line 19 def start return unless inactive? @thread = Thread.new do start_worker_loop end end |
#waiting? ⇒ Boolean
Returns true if the pool worker is waiting for tasks
47 48 49 |
# File 'lib/contender/pool/pool_worker.rb', line 47 def waiting? :waiting == @state end |