class Concurrent::OneByOne

never running at the same time.
Ensures that jobs are passed to the underlying executor one by one,

def call_job(job)

def call_job(job)
  job.executor.post { work(job) }
end

def initialize

def initialize
  @being_executed = false
  @stash          = []
  @mutex          = Mutex.new
end

def post(executor, *args, &task)

Raises:
  • (ArgumentError) - if no task is given

Returns:
  • (Boolean) - `true` if the task is queued, `false` if the executor

Other tags:
    Yield: - the asynchronous task to perform

Parameters:
  • args (Array) -- zero or more arguments to be passed to the task
  • executor (Executor) -- to be used for this job
def post(executor, *args, &task)
  return nil if task.nil?
  job = Job.new executor, args, task
  @mutex.lock
  post = if @being_executed
           @stash << job
           false
         else
           @being_executed = true
         end
  @mutex.unlock
  call_job job if post
  true
end

def work(job)

ensures next job is executed if any is stashed
def work(job)
  job.call
ensure
  @mutex.lock
  job = @stash.shift || (@being_executed = false)
  @mutex.unlock
  call_job job if job
end