Module: Concurrent::OptionsParser

Extended by:
OptionsParser
Included in:
OptionsParser
Defined in:
lib/concurrent/options_parser.rb

Overview

A mixin module for parsing options hashes related to gem-level configuration.

Instance Method Summary collapse

Instance Method Details

#get_executor_from(opts = {}) ⇒ Executor?

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

Options Hash (opts):

  • :executor (Executor) — default: `nil`

    when set use the given ‘Executor` instance

  • :operation (Boolean) — default: `false`

    when true use the global operation pool

  • :task (Boolean) — default: `true`

    when true use the global task pool



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/concurrent/options_parser.rb', line 14

def get_executor_from(opts = {})
  if opts[:executor]
    opts[:executor]
  elsif opts[:operation] == true || opts[:task] == false
    Concurrent.configuration.global_operation_pool
  elsif opts[:operation] == false || opts[:task] == true
    Concurrent.configuration.global_task_pool
  else
    nil
  end
end

#get_operation_executor_from(opts = {}) ⇒ Executor

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

Options Hash (opts):

  • :task_executor (Executor) — default: `nil`

    when set use the given ‘Executor` instance



42
43
44
# File 'lib/concurrent/options_parser.rb', line 42

def get_operation_executor_from(opts = {})
  opts[:operation_executor] || opts[:executor] || Concurrent.configuration.global_operation_pool
end

#get_task_executor_from(opts = {}) ⇒ Executor

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

Options Hash (opts):

  • :task_executor (Executor) — default: `nil`

    when set use the given ‘Executor` instance



32
33
34
# File 'lib/concurrent/options_parser.rb', line 32

def get_task_executor_from(opts = {})
  opts[:task_executor] || opts[:executor] || Concurrent.configuration.global_task_pool
end