Parent

Methods

Included Modules

Files

Class/Module Index [+]

Quicksearch

Concurrent::SerializedExecution

Ensures passed jobs in a serialized order never running at the same time.

Constants

Job

Public Class Methods

new() click to toggle source
# File lib/concurrent/executor/serialized_execution.rb, line 11
def initialize()
  super()
  synchronize { ns_initialize }
end

Public Instance Methods

post(executor, *args, &task) click to toggle source

Submit a task to the executor for asynchronous processing.

@param [Executor] executor to be used for this job

@param [Array] args zero or more arguments to be passed to the task

@yield the asynchronous task to perform

@return [Boolean] `true` if the task is queued, `false` if the executor

is not running

@raise [ArgumentError] if no task is given

# File lib/concurrent/executor/serialized_execution.rb, line 34
def post(executor, *args, &task)
  posts [[executor, args, task]]
  true
end
posts(posts) click to toggle source

As {post} but allows to submit multiple tasks at once, it's guaranteed that they will not be interleaved by other tasks.

@param [Array<Array(ExecutorService, Array<Object>, Proc)>] posts array of triplets where

first is a {ExecutorService}, second is array of args for task, third is a task (Proc)
# File lib/concurrent/executor/serialized_execution.rb, line 44
def posts(posts)
  # if can_overflow?
  #   raise ArgumentError, 'SerializedExecution does not support thread-pools which can overflow'
  # end

  return nil if posts.empty?

  jobs = posts.map { |executor, args, task| Job.new executor, args, task }

  job_to_post = synchronize do
    if @being_executed
      @stash.push(*jobs)
      nil
    else
      @being_executed = true
      @stash.push(*jobs[1..-1])
      jobs.first
    end
  end

  call_job job_to_post if job_to_post
  true
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.