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
410 def self.define_async_args_or_block_method(mod, method)
411   mod.send(:define_method, method) do |*args, &block|
412     if (block || !args.empty?) && @opts[:async]
413       ds = sync
414       db.send(:async_run){ds.send(method, *args, &block)}
415     else
416       super(*args, &block)
417     end
418   end
419 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
397 def self.define_async_block_method(mod, method)
398   mod.send(:define_method, method) do |*args, &block|
399     if block && @opts[:async]
400       ds = sync
401       db.send(:async_run){ds.send(method, *args, &block)}
402     else
403       super(*args, &block)
404     end
405   end
406 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
384 def self.define_async_method(mod, method)
385   mod.send(:define_method, method) do |*args, &block|
386     if @opts[:async]
387       ds = sync
388       db.send(:async_run){ds.send(method, *args, &block)}
389     else
390       super(*args, &block)
391     end
392   end
393 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
429 def async
430   cached_dataset(:_async) do
431     clone(:async=>true)
432   end
433 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
437 def sync
438   cached_dataset(:_sync) do
439     clone(:async=>false)
440   end
441 end