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