async-http-faraday 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c569036046b86acaf015c423fc888862d5354a33bcf6699c9d2ff9862a96a30
4
- data.tar.gz: 585cebc0227475f76d7686c2291ed9fcf358423ac0b505a4d2b5fa34273a9288
3
+ metadata.gz: 405bbaf8e19d542be2efd5e6ba29e5dabaa0fedbbad6c392f70b70dac5295f21
4
+ data.tar.gz: 2ae52a3a031dea0f6c715e7144f9e0ed2872b0e9b2c8a07043ce1be49f8640a5
5
5
  SHA512:
6
- metadata.gz: 3a032c25d0a49d7b02d32f93fa597ecc81562252efbf29f52ab70eafbc7b0e27ed68840118fb4b4c002ef6bc884365111ffcae3864dc8750cdf72789a5a18bae
7
- data.tar.gz: 221d129c86685d6e3ed610b10403fda786f6782c8e6ae24cf7337afbf9e6c01461e2fc10e1e2964a95e49be45714bf2510560a5ca4abf3a029894a09702e5437
6
+ metadata.gz: 8808afa0006650011169d8a9ea52d7029e8e7032d84eceec7e2fa2046b58e66297c3a5b0166ed623b81198161e5a5830309b4db21e30e9174d69f21927bb0a6f
7
+ data.tar.gz: '064528fe335006b4b00ba6719c119bf583c0cfb20ebdf67d74324d98c74d1c95c3bd9d00359ae1bf80d1fdaca796203526c95473a1d392128eff66b392770dba'
checksums.yaml.gz.sig CHANGED
Binary file
data/changes.md ADDED
@@ -0,0 +1,38 @@
1
+ # v0.18.0
2
+
3
+ ## Config Block
4
+
5
+ The `config_block` provided to the adapter must now return `nil`, `client` or a middleware wrapper around `client`.
6
+
7
+ ```ruby
8
+ Faraday.new do |builder|
9
+ builder.adapter :async_http do |client|
10
+ # Option 1 (same as returning `nil`), use client as is:
11
+ client # Use `client` as is.
12
+
13
+ # Option 2, wrap client in a middleware:
14
+ Async::HTTP::Middleware::LocationRedirector.new(client)
15
+ end
16
+ end
17
+ ```
18
+
19
+ # v0.17.0
20
+
21
+ ## Per-thread Client Cache
22
+
23
+ The default adapter now uses a per-thread client cache internally, to improve compatibility with existing code that shares a single `Faraday::Connection` instance across multiple threads.
24
+
25
+ ```ruby
26
+ adapter = Faraday.new do |builder|
27
+ builder.adapter :async_http
28
+ end
29
+
30
+ 3.times do
31
+ Thread.new do
32
+ Async do
33
+ # Each thread has it's own client cache.
34
+ adapter.get('http://example.com')
35
+ end
36
+ end
37
+ end
38
+ ```
@@ -12,6 +12,8 @@
12
12
 
13
13
  require 'faraday'
14
14
  require 'faraday/adapter'
15
+
16
+ require 'async/barrier'
15
17
  require 'kernel/sync'
16
18
 
17
19
  require 'async/http/client'
@@ -48,8 +50,47 @@ module Async
48
50
  end
49
51
  end
50
52
 
53
+ class ParallelManager
54
+ def initialize(options = {})
55
+ @options = options
56
+ @barrier = nil
57
+ end
58
+
59
+ def run
60
+ if $VERBOSE
61
+ warn "Please update your Faraday version!", uplevel: 2
62
+ end
63
+ end
64
+
65
+ def async(&block)
66
+ if @barrier
67
+ @barrier.async(&block)
68
+ else
69
+ Sync(&block)
70
+ end
71
+ end
72
+
73
+ def execute(&block)
74
+ Sync do
75
+ @barrier = Async::Barrier.new
76
+
77
+ yield
78
+
79
+ @barrier.wait
80
+ ensure
81
+ @barrier&.stop
82
+ end
83
+ end
84
+ end
85
+
51
86
  # An adapter that allows Faraday to use Async::HTTP as the underlying HTTP client.
52
87
  class Adapter < ::Faraday::Adapter
88
+ self.supports_parallel = true
89
+
90
+ def self.setup_parallel_manager(**options)
91
+ ParallelManager.new(options)
92
+ end
93
+
53
94
  # The exceptions that are considered connection errors and result in a `Faraday::ConnectionFailed` exception.
54
95
  CONNECTION_EXCEPTIONS = [
55
96
  Errno::EADDRNOTAVAIL,
@@ -98,6 +139,21 @@ module Async
98
139
  # For compatibility with the default adapter:
99
140
  env.url.path = '/' if env.url.path.empty?
100
141
 
142
+ if parallel_manager = env.parallel_manager
143
+ parallel_manager.async do
144
+ perform_request(env)
145
+ env.response.finish(env)
146
+ end
147
+ else
148
+ perform_request(env)
149
+ end
150
+
151
+ @app.call(env)
152
+ end
153
+
154
+ private
155
+
156
+ def perform_request(env)
101
157
  with_client(env) do |endpoint, client|
102
158
  if body = env.body
103
159
  # We need to ensure the body is wrapped in a Readable object so that it can be read in chunks:
@@ -149,8 +205,6 @@ module Async
149
205
  raise ::Faraday::ConnectionFailed, e
150
206
  end
151
207
 
152
- private
153
-
154
208
  def with_client(env)
155
209
  Sync do
156
210
  endpoint = Endpoint.new(env.url)
@@ -38,8 +38,8 @@ module Async
38
38
  # @parameter endpoint [IO::Endpoint::Generic] The endpoint to create the client for.
39
39
  def make_client(endpoint)
40
40
  client = Client.new(endpoint, **@options)
41
- @block&.call(client)
42
- return client
41
+
42
+ return @block&.call(client) || client
43
43
  end
44
44
 
45
45
  # Get a client for the given endpoint.
@@ -6,7 +6,7 @@
6
6
  module Async
7
7
  module HTTP
8
8
  module Faraday
9
- VERSION = "0.17.0"
9
+ VERSION = "0.19.0"
10
10
  end
11
11
  end
12
12
  end
data/readme.md CHANGED
@@ -9,9 +9,21 @@ Provides an adaptor for [Faraday](https://github.com/lostisland/faraday) to perf
9
9
 
10
10
  ## Usage
11
11
 
12
- Please see the [project documentation](https://socketry.github.io/async-http/) for more details.
12
+ Please see the [project documentation](https://socketry.github.io/async-http-faraday/) for more details.
13
13
 
14
- - [Getting Started](https://socketry.github.io/async-http/guides/getting-started/index) - This guide explains how to use use `Async::HTTP::Faraday` as a drop-in replacement for improved concurrency.
14
+ - [Getting Started](https://socketry.github.io/async-http-faraday/guides/getting-started/index) - This guide explains how to use use `Async::HTTP::Faraday` as a drop-in replacement for improved concurrency.
15
+
16
+ ## Releases
17
+
18
+ Please see the [project changes](https://socketry.github.io/async-http-faraday//changes/index) for all releases.
19
+
20
+ ### v0.18.0
21
+
22
+ - [Config Block](https://socketry.github.io/async-http-faraday/changes/index#config-block)
23
+
24
+ ### v0.17.0
25
+
26
+ - [Per-thread Client Cache](https://socketry.github.io/async-http-faraday/changes/index#per-thread-client-cache)
15
27
 
16
28
  ## Contributing
17
29
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-http-faraday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -46,7 +46,7 @@ cert_chain:
46
46
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
47
47
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
48
48
  -----END CERTIFICATE-----
49
- date: 2024-08-13 00:00:00.000000000 Z
49
+ date: 2024-08-22 00:00:00.000000000 Z
50
50
  dependencies:
51
51
  - !ruby/object:Gem::Dependency
52
52
  name: async-http
@@ -82,6 +82,7 @@ executables: []
82
82
  extensions: []
83
83
  extra_rdoc_files: []
84
84
  files:
85
+ - changes.md
85
86
  - examples/topics.rb
86
87
  - lib/async/http/faraday.rb
87
88
  - lib/async/http/faraday/adapter.rb
@@ -90,11 +91,12 @@ files:
90
91
  - lib/async/http/faraday/version.rb
91
92
  - license.md
92
93
  - readme.md
93
- homepage: https://github.com/socketry/async-http
94
+ homepage: https://github.com/socketry/async-http-faraday
94
95
  licenses:
95
96
  - MIT
96
97
  metadata:
97
- documentation_uri: https://socketry.github.io/async-http/
98
+ documentation_uri: https://socketry.github.io/async-http-faraday/
99
+ funding_uri: https://github.com/sponsors/ioquatix
98
100
  source_code_uri: https://github.com/socketry/async-http.git
99
101
  post_install_message:
100
102
  rdoc_options: []
metadata.gz.sig CHANGED
Binary file