Class: Koine::RestClient::AsyncBuilder
- Inherits:
-
Object
- Object
- Koine::RestClient::AsyncBuilder
- Defined in:
- lib/koine/rest_client/async_builder.rb
Overview
takes care of async requests
Instance Method Summary collapse
- #delete(*args, &block) ⇒ Object
- #get(*args, &block) ⇒ Object
-
#initialize(client, response_parser, queue = AsyncQueue.new) ⇒ AsyncBuilder
constructor
A new instance of AsyncBuilder.
- #on_error(&block) ⇒ Object
- #parsed_responses ⇒ Object
- #patch(*args, &block) ⇒ Object
- #post(*args, &block) ⇒ Object
- #put(*args, &block) ⇒ Object
Constructor Details
#initialize(client, response_parser, queue = AsyncQueue.new) ⇒ AsyncBuilder
Returns a new instance of AsyncBuilder.
7 8 9 10 11 12 13 14 |
# File 'lib/koine/rest_client/async_builder.rb', line 7 def initialize(client, response_parser, queue = AsyncQueue.new) @client = client @response_parser = response_parser @queue = queue @error_handler = proc do |error| raise error end end |
Instance Method Details
#delete(*args, &block) ⇒ Object
32 33 34 |
# File 'lib/koine/rest_client/async_builder.rb', line 32 def delete(*args, &block) queue(:delete, *args, &block) end |
#get(*args, &block) ⇒ Object
16 17 18 |
# File 'lib/koine/rest_client/async_builder.rb', line 16 def get(*args, &block) queue(:get, *args, &block) end |
#on_error(&block) ⇒ Object
46 47 48 |
# File 'lib/koine/rest_client/async_builder.rb', line 46 def on_error(&block) @error_handler = block end |
#parsed_responses ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/koine/rest_client/async_builder.rb', line 36 def parsed_responses blocks = @queue.map { |_request, block| block } threads = @queue.map do |request| Thread.new { @client.perform_request(request) } end @queue.clear responses = threads.map(&:value) parse_responses(responses, blocks) end |
#patch(*args, &block) ⇒ Object
28 29 30 |
# File 'lib/koine/rest_client/async_builder.rb', line 28 def patch(*args, &block) queue(:patch, *args, &block) end |
#post(*args, &block) ⇒ Object
20 21 22 |
# File 'lib/koine/rest_client/async_builder.rb', line 20 def post(*args, &block) queue(:post, *args, &block) end |
#put(*args, &block) ⇒ Object
24 25 26 |
# File 'lib/koine/rest_client/async_builder.rb', line 24 def put(*args, &block) queue(:put, *args, &block) end |