Class: Garcon::RubySingleThreadExecutor

Inherits:
Object
  • Object
show all
Includes:
RubyExecutor, SerialExecutor
Defined in:
lib/garcon/task/single_thread_executor.rb

Constant Summary

Constants included from RubyExecutor

Garcon::RubyExecutor::FALLBACK_POLICY

Instance Attribute Summary

Attributes included from Executor

#fallback_policy

Instance Method Summary collapse

Methods included from SerialExecutor

#serialized?

Methods included from Executor

#auto_terminate?, #can_overflow?, #serialized?

Methods included from RubyExecutor

#<<, #kill, #post, #running?, #shutdown, #shutdown?, #shuttingdown?, #wait_for_termination

Constructor Details

#initialize(opts = {}) ⇒ RubySingleThreadExecutor

Create a new thread pool.

Parameters:

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

    a customizable set of options

Options Hash (opts):

  • :fallback_policy (Symbol) — default: :discard

    The policy for handling new tasks that are received when the queue size has reached ‘max_queue` or after the executor has shut down.



34
35
36
37
38
39
40
41
42
43
# File 'lib/garcon/task/single_thread_executor.rb', line 34

def initialize(opts = {})
  @queue  = Queue.new
  @thread = nil
  @fallback_policy = opts.fetch(:fallback_policy, :discard)
  if !FALLBACK_POLICY.include?(fallback)
    raise ArgumentError, "#{fallback} is not a valid fallback policy"
  end
  init_executor
  enable_at_exit_handler!(opts)
end