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
346 def self.extended(db)
347   db.instance_exec do
348     case pool.pool_type
349     when :single, :sharded_single
350       raise Error, "cannot load async_thread_pool extension if using single or sharded_single connection pool"
351     end
352 
353     num_async_threads = opts[:num_async_threads] ? typecast_value_integer(opts[:num_async_threads]) : (Integer(opts[:max_connections] || 4))
354     raise Error, "must have positive number for num_async_threads" if num_async_threads <= 0
355 
356     proxy_klass = typecast_value_boolean(opts[:preempt_async_thread]) ? PreemptableProxy : Proxy
357     define_singleton_method(:async_job_class){proxy_klass}
358 
359     queue = @async_thread_queue = Queue.new
360     pool = @async_thread_pool = num_async_threads.times.map{JobProcessor.new(queue)}
361     ObjectSpace.define_finalizer(db, JobProcessor.create_finalizer(queue, pool))
362 
363     extend_datasets(DatasetMethods)
364   end
365 end