class Concurrent::AbstractExecutorService

@!macro abstract_executor_service_public_api @!visibility private

Constants

FALLBACK_POLICIES

The set of possible fallback policies that may be set at thread pool creation.

Attributes

fallback_policy[R]

@!macro executor_service_attr_reader_fallback_policy

name[R]

Public Class Methods

new(opts = {}, &block) click to toggle source

Create a new thread pool.

Calls superclass method
# File lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb, line 23
def initialize(opts = {}, &block)
  super(&nil)
  synchronize do
    @auto_terminate = opts.fetch(:auto_terminate, true)
    @name = opts.fetch(:name) if opts.key?(:name)
    ns_initialize(opts, &block)
  end
end

Public Instance Methods

auto_terminate=(value) click to toggle source

@!macro executor_service_method_auto_terminate_setter

# File lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb, line 72
def auto_terminate=(value)
  deprecated "Method #auto_terminate= has no effect. Set :auto_terminate option when executor is initialized."
end
auto_terminate?() click to toggle source

@!macro executor_service_method_auto_terminate_question

# File lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb, line 67
def auto_terminate?
  synchronize { @auto_terminate }
end
kill() click to toggle source

@!macro executor_service_method_kill

# File lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb, line 42
def kill
  raise NotImplementedError
end
running?() click to toggle source

@!macro executor_service_method_running_question

# File lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb, line 52
def running?
  synchronize { ns_running? }
end
shutdown() click to toggle source

@!macro executor_service_method_shutdown

# File lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb, line 37
def shutdown
  raise NotImplementedError
end
shutdown?() click to toggle source

@!macro executor_service_method_shutdown_question

# File lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb, line 62
def shutdown?
  synchronize { ns_shutdown? }
end
shuttingdown?() click to toggle source

@!macro executor_service_method_shuttingdown_question

# File lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb, line 57
def shuttingdown?
  synchronize { ns_shuttingdown? }
end
to_s() click to toggle source
Calls superclass method
# File lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb, line 32
def to_s
  name ? "#{super[0..-2]} name: #{name}>" : super
end
wait_for_termination(timeout = nil) click to toggle source

@!macro executor_service_method_wait_for_termination

# File lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb, line 47
def wait_for_termination(timeout = nil)
  raise NotImplementedError
end

Private Instance Methods

fallback_action(*args) { |*args| ... } click to toggle source

Returns an action which executes the ‘fallback_policy` once the queue size reaches `max_queue`. The reason for the indirection of an action is so that the work can be deferred outside of synchronization.

@param [Array] args the arguments to the task which is being handled.

@!visibility private

# File lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb, line 85
def fallback_action(*args)
  case fallback_policy
  when :abort
    lambda { raise RejectedExecutionError }
  when :discard
    lambda { false }
  when :caller_runs
    lambda {
      begin
        yield(*args)
      rescue => ex
        # let it fail
        log DEBUG, ex
      end
      true
    }
  else
    lambda { fail "Unknown fallback policy #{fallback_policy}" }
  end
end
ns_auto_terminate?() click to toggle source
# File lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb, line 126
def ns_auto_terminate?
  @auto_terminate
end
ns_execute(*args, &task) click to toggle source
# File lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb, line 106
def ns_execute(*args, &task)
  raise NotImplementedError
end
ns_kill_execution() click to toggle source

@!macro executor_service_method_ns_kill_execution

Callback method called when the executor has been killed.
The default behavior is to do nothing.
# File lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb, line 122
def ns_kill_execution
  # do nothing
end
ns_shutdown_execution() click to toggle source

@!macro executor_service_method_ns_shutdown_execution

Callback method called when an orderly shutdown has completed.
The default behavior is to signal all waiting threads.
# File lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb, line 114
def ns_shutdown_execution
  # do nothing
end