module Sequel::Database::AsyncThreadPool::DatabaseMethods

Public Class Methods

extended(db) click to toggle 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

Private Instance Methods

async_run(&block) click to toggle source

Wrap the block in a job/proxy object and schedule it to run using the async thread pool.

    # File lib/sequel/extensions/async_thread_pool.rb
362 def async_run(&block)
363   proxy = async_job_class.new(&block)
364   @async_thread_queue.push(proxy)
365   proxy
366 end