module Sequel::Database::AsyncThreadPool::DatasetMethods

  1. lib/sequel/extensions/async_thread_pool.rb

Public Class methods

define_async_args_or_block_method(mod, method)

Define an method in the given module that will run the given method using an async thread if the current dataset is async and arguments or a block is provided.

[show source]
    # File lib/sequel/extensions/async_thread_pool.rb
402 def self.define_async_args_or_block_method(mod, method)
403   mod.send(:define_method, method) do |*args, &block|
404     if (block || !args.empty?) && @opts[:async]
405       ds = sync
406       db.send(:async_run){ds.send(method, *args, &block)}
407     else
408       super(*args, &block)
409     end
410   end
411 end
define_async_block_method(mod, method)

Define an method in the given module that will run the given method using an async thread if the current dataset is async and a block is provided.

[show source]
    # File lib/sequel/extensions/async_thread_pool.rb
389 def self.define_async_block_method(mod, method)
390   mod.send(:define_method, method) do |*args, &block|
391     if block && @opts[:async]
392       ds = sync
393       db.send(:async_run){ds.send(method, *args, &block)}
394     else
395       super(*args, &block)
396     end
397   end
398 end
define_async_method(mod, method)

Define an method in the given module that will run the given method using an async thread if the current dataset is async.

[show source]
    # File lib/sequel/extensions/async_thread_pool.rb
376 def self.define_async_method(mod, method)
377   mod.send(:define_method, method) do |*args, &block|
378     if @opts[:async]
379       ds = sync
380       db.send(:async_run){ds.send(method, *args, &block)}
381     else
382       super(*args, &block)
383     end
384   end
385 end

Public Instance methods

async()

Return a cloned dataset that will load results using the async thread pool.

[show source]
    # File lib/sequel/extensions/async_thread_pool.rb
421 def async
422   cached_dataset(:_async) do
423     clone(:async=>true)
424   end
425 end
sync()

Return a cloned dataset that will not load results using the async thread pool. Only used if the current dataset has been marked as using the async thread pool.

[show source]
    # File lib/sequel/extensions/async_thread_pool.rb
429 def sync
430   cached_dataset(:_sync) do
431     clone(:async=>false)
432   end
433 end