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