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