Class: Wrest::AsyncRequest::ThreadBackend
- Inherits:
-
Object
- Object
- Wrest::AsyncRequest::ThreadBackend
- Defined in:
- lib/wrest/async_request/thread_backend.rb
Overview
Uses a pool of Threads to make requests. Only recommended for production use on JRuby.
Instance Attribute Summary collapse
-
#thread_pool ⇒ Object
readonly
Returns the value of attribute thread_pool.
Instance Method Summary collapse
- #execute(request) ⇒ Object
-
#initialize(number_of_threads = 5) ⇒ ThreadBackend
constructor
A new instance of ThreadBackend.
-
#wait_for_thread_pool! ⇒ Object
Uses Thread#join to wait until all background requests are completed.
Constructor Details
#initialize(number_of_threads = 5) ⇒ ThreadBackend
Returns a new instance of ThreadBackend.
19 20 21 |
# File 'lib/wrest/async_request/thread_backend.rb', line 19 def initialize(number_of_threads = 5) @thread_pool = ThreadPool.new(number_of_threads) end |
Instance Attribute Details
#thread_pool ⇒ Object (readonly)
Returns the value of attribute thread_pool.
17 18 19 |
# File 'lib/wrest/async_request/thread_backend.rb', line 17 def thread_pool @thread_pool end |
Instance Method Details
#execute(request) ⇒ Object
23 24 25 |
# File 'lib/wrest/async_request/thread_backend.rb', line 23 def execute(request) @thread_pool.execute_eventually(request) end |
#wait_for_thread_pool! ⇒ Object
Uses Thread#join to wait until all background requests are completed.
29 30 31 |
# File 'lib/wrest/async_request/thread_backend.rb', line 29 def wait_for_thread_pool! @thread_pool.join_pool_threads! end |