Module: Pgbus::ExecutionPools

Defined in:
lib/pgbus/execution_pools.rb,
lib/pgbus/execution_pools/async_pool.rb,
lib/pgbus/execution_pools/thread_pool.rb

Defined Under Namespace

Classes: AsyncPool, ThreadPool

Class Method Summary collapse

Class Method Details

.build(mode:, capacity:, on_state_change: nil) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/pgbus/execution_pools.rb', line 6

def build(mode:, capacity:, on_state_change: nil)
  case normalize_mode(mode)
  when :threads
    ThreadPool.new(capacity: capacity, on_state_change: on_state_change)
  when :async
    AsyncPool.new(capacity: capacity, on_state_change: on_state_change)
  end
end

.normalize_mode(mode) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/pgbus/execution_pools.rb', line 15

def normalize_mode(mode)
  case mode.to_s
  when "", "threads"
    :threads
  when "async", "fiber"
    :async
  else
    raise ArgumentError, "Unknown execution_mode: #{mode.inspect}. Expected one of: :threads, :async, :fiber"
  end
end