Class: Contender::Pool::PoolWorker

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/contender/pool/pool_worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_countObject (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

#threadObject (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

#interruptObject



31
32
33
# File 'lib/contender/pool/pool_worker.rb', line 31

def interrupt
  @thread.raise Interrupt
end

#on_task_completionObject



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