Class: TVDB::Service::Threading::ThreadedRequest
- Inherits:
-
Object
- Object
- TVDB::Service::Threading::ThreadedRequest
- Defined in:
- lib/tvdb_client/service/threading/threaded_request.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#pool_size ⇒ Object
readonly
Returns the value of attribute pool_size.
-
#threads ⇒ Object
Returns the value of attribute threads.
Instance Method Summary collapse
-
#initialize(options) ⇒ ThreadedRequest
constructor
A new instance of ThreadedRequest.
- #make_request(route) ⇒ Object
Constructor Details
#initialize(options) ⇒ ThreadedRequest
Returns a new instance of ThreadedRequest.
9 10 11 12 13 |
# File 'lib/tvdb_client/service/threading/threaded_request.rb', line 9 def initialize( ) @connection = .fetch( :connection ) @pool_size = .fetch( :pool_size ) { 10 } @threads = Array.new end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/tvdb_client/service/threading/threaded_request.rb', line 6 def connection @connection end |
#pool_size ⇒ Object (readonly)
Returns the value of attribute pool_size.
6 7 8 |
# File 'lib/tvdb_client/service/threading/threaded_request.rb', line 6 def pool_size @pool_size end |
#threads ⇒ Object
Returns the value of attribute threads.
7 8 9 |
# File 'lib/tvdb_client/service/threading/threaded_request.rb', line 7 def threads @threads end |
Instance Method Details
#make_request(route) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tvdb_client/service/threading/threaded_request.rb', line 15 def make_request( route ) response = connection.get( route ) return response if response.code != 200 links = connection.get( route ).body["links"] first_page = links["first"] last_page = links["last"] @results = Array.new for page in first_page..last_page manage_thread_pool threads << Thread.new( page ) do |page_num| params = { :params => { page: page_num } } @results << connection.get( route, params ).body["data"] end end threads.each { |thread| thread.join } return @results.flatten end |