async-http-faraday 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b306179751e2a8f56e9f63b68b243f8ae504b8c7a79f2c00ecd98fc1e09d9ba
4
- data.tar.gz: c5aef891d4ba786d2e489c847c021a00bb47c8b0096ad07b595184bf8cd96caf
3
+ metadata.gz: 405bbaf8e19d542be2efd5e6ba29e5dabaa0fedbbad6c392f70b70dac5295f21
4
+ data.tar.gz: 2ae52a3a031dea0f6c715e7144f9e0ed2872b0e9b2c8a07043ce1be49f8640a5
5
5
  SHA512:
6
- metadata.gz: 2faccb555f15488e99cc9f3b774dd9aae4eb9b3dac432623a85cf5c85019fa223cf0fe3538fb1e82cef67400f6d4ec86fc41ec8530a95effc69364fa50a99bf3
7
- data.tar.gz: 4ea301d64d6bd6716eae5f7bbdb6569a31a4d51b9ac023a30f153ff248e87420c454966fb05cecd44acfad0a614690ada231b9d4ef6508f4ec53c4b87ee24a07
6
+ metadata.gz: 8808afa0006650011169d8a9ea52d7029e8e7032d84eceec7e2fa2046b58e66297c3a5b0166ed623b81198161e5a5830309b4db21e30e9174d69f21927bb0a6f
7
+ data.tar.gz: '064528fe335006b4b00ba6719c119bf583c0cfb20ebdf67d74324d98c74d1c95c3bd9d00359ae1bf80d1fdaca796203526c95473a1d392128eff66b392770dba'
checksums.yaml.gz.sig CHANGED
Binary file
data/changes.md CHANGED
@@ -15,3 +15,24 @@ Faraday.new do |builder|
15
15
  end
16
16
  end
17
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)
@@ -6,7 +6,7 @@
6
6
  module Async
7
7
  module HTTP
8
8
  module Faraday
9
- VERSION = "0.18.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.18.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-17 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
@@ -91,11 +91,12 @@ files:
91
91
  - lib/async/http/faraday/version.rb
92
92
  - license.md
93
93
  - readme.md
94
- homepage: https://github.com/socketry/async-http
94
+ homepage: https://github.com/socketry/async-http-faraday
95
95
  licenses:
96
96
  - MIT
97
97
  metadata:
98
- 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
99
100
  source_code_uri: https://github.com/socketry/async-http.git
100
101
  post_install_message:
101
102
  rdoc_options: []
metadata.gz.sig CHANGED
Binary file