Method: Contender::Pool::PoolExecutor#execute

Defined in:
lib/contender/pool/pool_executor.rb

#execute(task = nil, &block) ⇒ undefined

Parameters:

  • task (Object) (defaults to: nil)

Returns:

  • (undefined)

Raises:



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/contender/pool/pool_executor.rb', line 78

def execute(task = nil, &block)
  task ||= block

  raise ArgumentError unless task

  return if try_core_worker task

  # Core worker couldn't be started with the task; enqueue it instead
  control = current_control

  if control.state == RUNNING && @queue.offer(task)
    after_task_enqueue task
    return
  end

  # Either the pool is shutting down or the queue is full
  unless add_worker false, task
    reject task
  end
end