Module: Sequel::Database::AsyncThreadPool::DatabaseMethods

Defined in:
lib/sequel/extensions/async_thread_pool.rb

Class Method Summary collapse

Class Method Details

.extended(db) ⇒ Object


339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/sequel/extensions/async_thread_pool.rb', line 339

def self.extended(db)
  db.instance_exec do
    unless pool.pool_type == :threaded || pool.pool_type == :sharded_threaded
      raise Error, "can only load async_thread_pool extension if using threaded or sharded_threaded 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 = num_async_threads.times.map{JobProcessor.new(queue)}
    ObjectSpace.define_finalizer(db, JobProcessor.create_finalizer(queue, pool))

    extend_datasets(DatasetMethods)
  end
end