Class: Concurrent::SerializedExecutionDelegator

Inherits:
SimpleDelegator
  • Object
show all
Includes:
SerialExecutor
Defined in:
lib/concurrent/executor/serialized_execution.rb

Overview

A wrapper/delegator for any ‘Executor` or `ExecutorService` that guarantees serialized execution of tasks.

Instance Method Summary collapse

Methods included from SerialExecutor

#serialized?

Methods included from Executor

#can_overflow?, #serialized?

Constructor Details

#initialize(executor) ⇒ SerializedExecutionDelegator

Returns a new instance of SerializedExecutionDelegator.



113
114
115
116
117
# File 'lib/concurrent/executor/serialized_execution.rb', line 113

def initialize(executor)
  @executor   = executor
  @serializer = SerializedExecution.new
  super(executor)
end

Instance Method Details

#post(*args) { ... } ⇒ Boolean

Submit a task to the executor for asynchronous processing.

Parameters:

  • args (Array)

    zero or more arguments to be passed to the task

Yields:

  • the asynchronous task to perform

Returns:

  • (Boolean)

    ‘true` if the task is queued, `false` if the executor is not running

Raises:

  • (ArgumentError)

    if no task is given



120
121
122
123
124
# File 'lib/concurrent/executor/serialized_execution.rb', line 120

def post(*args, &task)
  raise ArgumentError.new('no block given') unless block_given?
  return false unless running?
  @serializer.post(@executor, *args, &task)
end