module Garcon::ExecutorOptions

Public Instance Methods

get_executor_from(opts = {}) click to toggle source

Get the requested ‘Executor` based on the values set in the options hash.

@param [Hash] opts

The options defining the requested executor.

@option opts [Executor] :executor

When set use the given `Executor` instance. Three special values are
also supported: `:fast` returns the global fast executor, `:io` returns
the global io executor, and `:immediate` returns a new
`ImmediateExecutor` object.

@return [Executor, nil]

The requested thread pool, or nil when no option specified.

@!visibility private

# File lib/garcon/task/executor_options.rb, line 40
def get_executor_from(opts = {})
  if (executor = opts[:executor]).is_a? Symbol
    case opts[:executor]
    when :fast
      Garcon.global_fast_executor
    when :io
      Garcon.global_io_executor
    when :immediate
      Garcon::ImmediateExecutor.new
    else
      raise ArgumentError, "executor '#{executor}' not recognized"
    end
  elsif opts[:executor]
    opts[:executor]
  else
    nil
  end
end