Module: Sequel::Database::AsyncThreadPool::DatasetMethods
- Defined in:
- lib/sequel/extensions/async_thread_pool.rb
Class Method Summary collapse
-
.define_async_args_or_block_method(mod, method) ⇒ Object
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.
-
.define_async_block_method(mod, method) ⇒ Object
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.
-
.define_async_method(mod, method) ⇒ Object
Define an method in the given module that will run the given method using an async thread if the current dataset is async.
Instance Method Summary collapse
-
#async ⇒ Object
Return a cloned dataset that will load results using the async thread pool.
-
#sync ⇒ Object
Return a cloned dataset that will not load results using the async thread pool.
Class Method Details
.define_async_args_or_block_method(mod, method) ⇒ Object
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.
410 411 412 413 414 415 416 417 418 419 |
# File 'lib/sequel/extensions/async_thread_pool.rb', line 410 def self.define_async_args_or_block_method(mod, method) mod.send(:define_method, method) do |*args, &block| if (block || !args.empty?) && @opts[:async] ds = sync db.send(:async_run){ds.send(method, *args, &block)} else super(*args, &block) end end end |
.define_async_block_method(mod, method) ⇒ Object
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.
397 398 399 400 401 402 403 404 405 406 |
# File 'lib/sequel/extensions/async_thread_pool.rb', line 397 def self.define_async_block_method(mod, method) mod.send(:define_method, method) do |*args, &block| if block && @opts[:async] ds = sync db.send(:async_run){ds.send(method, *args, &block)} else super(*args, &block) end end end |
.define_async_method(mod, method) ⇒ Object
Define an method in the given module that will run the given method using an async thread if the current dataset is async.
384 385 386 387 388 389 390 391 392 393 |
# File 'lib/sequel/extensions/async_thread_pool.rb', line 384 def self.define_async_method(mod, method) mod.send(:define_method, method) do |*args, &block| if @opts[:async] ds = sync db.send(:async_run){ds.send(method, *args, &block)} else super(*args, &block) end end end |
Instance Method Details
#async ⇒ Object
Return a cloned dataset that will load results using the async thread pool.
429 430 431 432 433 |
# File 'lib/sequel/extensions/async_thread_pool.rb', line 429 def async cached_dataset(:_async) do clone(:async=>true) end end |
#sync ⇒ Object
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.
437 438 439 440 441 |
# File 'lib/sequel/extensions/async_thread_pool.rb', line 437 def sync cached_dataset(:_sync) do clone(:async=>false) end end |