Class: CobraCommander::Executor::WorkerPool::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/cobra_commander/executor/worker_pool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, pool) ⇒ Worker

Returns a new instance of Worker.



36
37
38
39
# File 'lib/cobra_commander/executor/worker_pool.rb', line 36

def initialize(id, pool)
  @id = id
  @pool = pool
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



34
35
36
# File 'lib/cobra_commander/executor/worker_pool.rb', line 34

def id
  @id
end

Instance Method Details

#killObject



41
42
43
# File 'lib/cobra_commander/executor/worker_pool.rb', line 41

def kill
  @thread&.kill
end

#spawnObject



45
46
47
48
49
# File 'lib/cobra_commander/executor/worker_pool.rb', line 45

def spawn
  @thread = Thread.new do
    loop { break if @pool.run_next == :exit }
  end
end

#waitObject



51
52
53
# File 'lib/cobra_commander/executor/worker_pool.rb', line 51

def wait
  @thread.join
end