Sha256: 7098422f08a20706bed5fa32af5892e517eddfdc914772ca1d5ecde47a169094

Contents?: true

Size: 947 Bytes

Versions: 54

Compression:

Stored size: 947 Bytes

Contents

require "concurrent"
require "thread"

module ActionSubscriber
  module ThreadPools
    MUTEX = ::Mutex.new
    THREADPOOL_DEFAULTS = {
      :auto_terminate => true,
      :fallback_policy => :caller_runs,
      :max_queue => 10_000,
    }.freeze

    def self.threadpools
      MUTEX.synchronize do
        @threadpools ||= {}
      end
    end

    def self.setup_threadpool(name, settings)
      MUTEX.synchronize do
        @threadpools ||= {}
        fail ArgumentError, "a #{name} threadpool already exists" if @threadpools.has_key?(name)
        @threadpools[name] = create_threadpool(settings)
      end
    end

    def self.create_threadpool(settings)
      settings = THREADPOOL_DEFAULTS.merge(settings)
      num_threads = settings.delete(:threadpool_size) || ::ActionSubscriber.configuration.threadpool_size
      ::Concurrent::FixedThreadPool.new(num_threads, settings)
    end
    private_class_method :create_threadpool
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
action_subscriber-5.3.3-java lib/action_subscriber/thread_pools.rb
action_subscriber-5.3.3 lib/action_subscriber/thread_pools.rb
action_subscriber-5.3.2-java lib/action_subscriber/thread_pools.rb
action_subscriber-5.3.2 lib/action_subscriber/thread_pools.rb
action_subscriber-5.3.1-java lib/action_subscriber/thread_pools.rb
action_subscriber-5.3.1 lib/action_subscriber/thread_pools.rb
action_subscriber-5.3.1.pre-java lib/action_subscriber/thread_pools.rb
action_subscriber-5.3.1.pre lib/action_subscriber/thread_pools.rb
action_subscriber-5.3.0-java lib/action_subscriber/thread_pools.rb
action_subscriber-5.3.0 lib/action_subscriber/thread_pools.rb
action_subscriber-5.2.4-java lib/action_subscriber/thread_pools.rb
action_subscriber-5.2.4 lib/action_subscriber/thread_pools.rb
action_subscriber-5.2.3-java lib/action_subscriber/thread_pools.rb
action_subscriber-5.2.3 lib/action_subscriber/thread_pools.rb
action_subscriber-5.2.2-java lib/action_subscriber/thread_pools.rb
action_subscriber-5.2.2 lib/action_subscriber/thread_pools.rb
action_subscriber-5.2.1-java lib/action_subscriber/thread_pools.rb
action_subscriber-5.2.1 lib/action_subscriber/thread_pools.rb
action_subscriber-5.2.0-java lib/action_subscriber/thread_pools.rb
action_subscriber-5.2.0 lib/action_subscriber/thread_pools.rb