module Sequel::Database::AsyncThreadPool::DatabaseMethods

  1. lib/sequel/extensions/async_thread_pool.rb

Methods

Public Class

  1. extended

Public Class methods

extended(db)
[show source]
    # File lib/sequel/extensions/async_thread_pool.rb
339 def self.extended(db)
340   db.instance_exec do
341     unless pool.pool_type == :threaded || pool.pool_type == :sharded_threaded
342       raise Error, "can only load async_thread_pool extension if using threaded or sharded_threaded connection pool"
343     end
344 
345     num_async_threads = opts[:num_async_threads] ? typecast_value_integer(opts[:num_async_threads]) : (Integer(opts[:max_connections] || 4))
346     raise Error, "must have positive number for num_async_threads" if num_async_threads <= 0
347 
348     proxy_klass = typecast_value_boolean(opts[:preempt_async_thread]) ? PreemptableProxy : Proxy
349     define_singleton_method(:async_job_class){proxy_klass}
350 
351     queue = @async_thread_queue = Queue.new
352     pool = @async_thread_pool = num_async_threads.times.map{JobProcessor.new(queue)}
353     ObjectSpace.define_finalizer(db, JobProcessor.create_finalizer(queue, pool))
354 
355     extend_datasets(DatasetMethods)
356   end
357 end