123456789_123456789_123456789_123456789_123456789_

Class: Concurrent::IndirectImmediateExecutor

Overview

Note:

Intended for use primarily in testing and debugging.

An executor service which runs all operations on a new thread, blocking until it completes. Operations are performed in the order they are received and no two operations can be performed simultaneously.

This executor service exists mainly for testing an debugging. When used it immediately runs every #post operation on a new thread, blocking the current thread until the operation is complete. This is similar to how the ImmediateExecutor works, but the operation has the full stack of the new thread at its disposal. This can be helpful when the operations will spawn more operations on the same executor and so on - such a situation might overflow the single stack in case of an ImmediateExecutor, which is inconsistent with how it would behave for a threaded executor.

Constant Summary

Concern::Logging - Included

SEV_LABEL

AbstractExecutorService - Inherited

FALLBACK_POLICIES

Class Method Summary

ImmediateExecutor - Inherited

.new

Creates a new executor.

AbstractExecutorService - Inherited

.new

Create a new thread pool.

Instance Attribute Summary

ImmediateExecutor - Inherited

#running?

Is the executor running?

#shutdown?

Is the executor shutdown?

#shuttingdown?

Is the executor shuttingdown?

SerialExecutorService - Included

#serialized?

Does this executor guarantee serialization of its operations?

AbstractExecutorService - Inherited

#auto_terminate=

Set the auto-terminate behavior for this executor.

#auto_terminate?

Is the executor auto-terminate when the application exits?

#fallback_policy, #name,
#running?

Is the executor running?

#shutdown

Begin an orderly shutdown.

#shutdown?

Is the executor shutdown?

#shuttingdown?

Is the executor shuttingdown?

#ns_auto_terminate?

ExecutorService - Included

#can_overflow?

Does the task queue have a maximum size?

#serialized?

Does this executor guarantee serialization of its operations?

Instance Method Summary

ImmediateExecutor - Inherited

#<<

Submit a task to the executor for asynchronous processing.

#kill
#post

Submit a task to the executor for asynchronous processing.

#shutdown

Begin an orderly shutdown.

#wait_for_termination

Block until executor shutdown is complete or until timeout seconds have passed.

AbstractExecutorService - Inherited

#<<

Submit a task to the executor for asynchronous processing.

#can_overflow?

Does the task queue have a maximum size?

#kill

Begin an immediate shutdown.

#post

Submit a task to the executor for asynchronous processing.

#serialized?

Does this executor guarantee serialization of its operations?

#to_s,
#wait_for_termination

Block until executor shutdown is complete or until timeout seconds have passed.

#fallback_action

Returns an action which executes the fallback_policy once the queue size reaches max_queue.

#ns_execute,
#ns_kill_execution

Callback method called when the executor has been killed.

#ns_shutdown_execution

Callback method called when an orderly shutdown has completed.

Concern::Deprecation - Included

ExecutorService - Included

#<<

Submit a task to the executor for asynchronous processing.

#post

Submit a task to the executor for asynchronous processing.

Concern::Logging - Included

#log

Logs through global_logger, it can be overridden by setting @logger.

Synchronization::LockableObject - Inherited

Constructor Details

.newIndirectImmediateExecutor

Creates a new executor

[ GitHub ]

  
# File 'lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb', line 21

def initialize
  super
  @internal_executor = SimpleExecutorService.new
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

[ GitHub ]

  
# File 'lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb', line 27

def post(*args, &task)
  raise ArgumentError.new("no block given") unless block_given?
  return false unless running?

  event = Concurrent::Event.new
  @internal_executor.post do
    begin
      task.call(*args)
    ensure
      event.set
    end
  end
  event.wait

  true
end