class Concurrent::WrappingExecutor

A delegating executor which modifies each task with arguments before the task is given to the target executor it delegates to. @example Count task executions

counter          = AtomicFixnum.new
count_executions = WrappingExecutor.new Concurrent.global_io_executor do |*args, &task|
  [*args, -> *args { counter.increment; task.call *args }]
end
10.times { count_executions.post { :do_something } }
sleep 0.01
counter.value #=> 10

Public Class Methods

new(executor, &wrapper) click to toggle source

@param [Executor] executor an executor to delegate the tasks to @yield [*args, &task] A function which can modify the task with arguments @yieldparam [Array<Object>] *args the arguments submitted with the tasks @yieldparam [block] &task the task submitted to the executor to be modified @yieldreturn [Array<Object>] a new arguments and task `[*args, task]` which are submitted to the target executor

Calls superclass method
# File lib/concurrent-ruby-edge/concurrent/executor/wrapping_executor.rb, line 23
def initialize(executor, &wrapper)
  super()
  @Wrapper  = wrapper
  @Executor = executor
end

Public Instance Methods

can_overflow?() click to toggle source

@!macro executor_service_method_can_overflow_question

# File lib/concurrent-ruby-edge/concurrent/executor/wrapping_executor.rb, line 38
def can_overflow?
  @Executor.can_overflow?
end
post(*args, &task) click to toggle source

@!macro executor_service_method_post

@see initialize how the tasks can be modified

# File lib/concurrent-ruby-edge/concurrent/executor/wrapping_executor.rb, line 32
def post(*args, &task)
  *args, task = @Wrapper.call(*args, &task)
  @Executor.post(*args, &task)
end
serialized?() click to toggle source

@!macro executor_service_method_serialized_question

# File lib/concurrent-ruby-edge/concurrent/executor/wrapping_executor.rb, line 43
def serialized?
  @Executor.serialized?
end