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.
16 17 18 |
# File 'lib/wrest/async_request/thread_backend.rb', line 16 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.
15 16 17 |
# File 'lib/wrest/async_request/thread_backend.rb', line 15 def thread_pool @thread_pool end |
Instance Method Details
#execute(request) ⇒ Object
20 21 22 |
# File 'lib/wrest/async_request/thread_backend.rb', line 20 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.
26 27 28 |
# File 'lib/wrest/async_request/thread_backend.rb', line 26 def wait_for_thread_pool! @thread_pool.join_pool_threads! end |