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.
403 404 405 406 407 408 409 410 411 412 |
# File 'lib/sequel/extensions/async_thread_pool.rb', line 403 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.
390 391 392 393 394 395 396 397 398 399 |
# File 'lib/sequel/extensions/async_thread_pool.rb', line 390 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.
377 378 379 380 381 382 383 384 385 386 |
# File 'lib/sequel/extensions/async_thread_pool.rb', line 377 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.
422 423 424 425 426 |
# File 'lib/sequel/extensions/async_thread_pool.rb', line 422 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.
430 431 432 433 434 |
# File 'lib/sequel/extensions/async_thread_pool.rb', line 430 def sync cached_dataset(:_sync) do clone(:async=>false) end end |