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.

Parameters:

  • opts (Hash) (defaults to: {})

    the options defining the requested executor

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

Returns:

  • (Executor)

    the requested thread pool (default: global task pool)



14
15
16
17
18
19
20
21
22
# 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
  else
    Concurrent.configuration.global_task_pool
  end
end

#get_operation_executor_from(opts = {}) ⇒ Executor

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

Parameters:

  • opts (Hash) (defaults to: {})

    the options defining the requested executor

Options Hash (opts):

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

    when set use the given ‘Executor` instance

Returns:

  • (Executor)

    the requested thread pool (default: global operation pool)



40
41
42
# File 'lib/concurrent/options_parser.rb', line 40

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.

Parameters:

  • opts (Hash) (defaults to: {})

    the options defining the requested executor

Options Hash (opts):

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

    when set use the given ‘Executor` instance

Returns:

  • (Executor)

    the requested thread pool (default: global task pool)



30
31
32
# File 'lib/concurrent/options_parser.rb', line 30

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