Module: Wrest::AsyncRequest
- Defined in:
- lib/wrest/async_request.rb,
lib/wrest/async_request/thread_pool.rb,
lib/wrest/async_request/thread_backend.rb,
lib/wrest/async_request/event_machine_backend.rb
Defined Under Namespace
Classes: EventMachineBackend, ThreadBackend, ThreadPool
Class Method Summary collapse
-
.default_backend ⇒ Object
Returns the default backend, which is the ThreadBackend.
-
.default_backend=(backend) ⇒ Object
Assign default backend to be used for asynchronous request.
-
.default_to_em! ⇒ Object
Assign default backend for asynchronous request to using eventmachine.
-
.default_to_threads!(number_of_threads = 5) ⇒ Object
Assign default backend for asynchronous request to using threads.
-
.enable_em ⇒ Object
Loads Wrest eventmachine backend alongwith eventmachine gem.
-
.wait_for_thread_pool! ⇒ Object
Uses Thread#join to wait until all background requests are completed.
Class Method Details
.default_backend ⇒ Object
Returns the default backend, which is the ThreadBackend
36 37 38 |
# File 'lib/wrest/async_request.rb', line 36 def self.default_backend @default_backend || default_to_threads! end |
.default_backend=(backend) ⇒ Object
Assign default backend to be used for asynchronous request. Default is to use threads
20 21 22 |
# File 'lib/wrest/async_request.rb', line 20 def self.default_backend=(backend) @default_backend = backend end |
.default_to_em! ⇒ Object
Assign default backend for asynchronous request to using eventmachine.
25 26 27 28 |
# File 'lib/wrest/async_request.rb', line 25 def self.default_to_em! enable_em self.default_backend = Wrest::AsyncRequest::EventMachineBackend.new end |
.default_to_threads!(number_of_threads = 5) ⇒ Object
Assign default backend for asynchronous request to using threads.
31 32 33 |
# File 'lib/wrest/async_request.rb', line 31 def self.default_to_threads!(number_of_threads = 5) self.default_backend = Wrest::AsyncRequest::ThreadBackend.new(number_of_threads) end |
.enable_em ⇒ Object
Loads Wrest eventmachine backend alongwith eventmachine gem
15 16 17 |
# File 'lib/wrest/async_request.rb', line 15 def self.enable_em require 'wrest/async_request/event_machine_backend' end |
.wait_for_thread_pool! ⇒ Object
Uses Thread#join to wait until all background requests are completed.
Use this as the last instruction in a script to prevent it from exiting before background threads have completed running.
Needs Wrest.default_backend to be an instance of ThreadBackend.
47 48 49 |
# File 'lib/wrest/async_request.rb', line 47 def self.wait_for_thread_pool! default_backend.wait_for_thread_pool! end |