mirror of
https://github.com/iv-org/invidious.git
synced 2025-04-27 15:30:35 +05:30
Pool: Make Pool#client method public
This commit is contained in:
parent
ebefa5e914
commit
f32c954859
@ -58,8 +58,24 @@ Spectator.describe Invidious::ConnectionPool do
|
|||||||
expect(pool.post("/post") { |r| r.body_io.gets_to_end }).to eq("post")
|
expect(pool.post("/post") { |r| r.body_io.gets_to_end }).to eq("post")
|
||||||
end
|
end
|
||||||
|
|
||||||
# it "Can checkout a client" do
|
it "Allows more than one clients to be checked out (if applicable)" do
|
||||||
# end
|
pool = Invidious::ConnectionPool::Pool.new(URI.parse("http://localhost:12345"), max_capacity: 100)
|
||||||
|
|
||||||
|
pool.checkout do | client |
|
||||||
|
expect(pool.post("/post").body).to eq("post")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "Can make multiple requests with the same client" do
|
||||||
|
pool = Invidious::ConnectionPool::Pool.new(URI.parse("http://localhost:12345"), max_capacity: 100)
|
||||||
|
|
||||||
|
pool.checkout do | client |
|
||||||
|
expect(client.get("/get").body).to eq("get")
|
||||||
|
expect(client.post("/post").body).to eq("post")
|
||||||
|
expect(client.get("/get").body).to eq("get")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
it "Allows concurrent requests" do
|
it "Allows concurrent requests" do
|
||||||
pool = Invidious::ConnectionPool::Pool.new(URI.parse("http://localhost:12345"), max_capacity: 100)
|
pool = Invidious::ConnectionPool::Pool.new(URI.parse("http://localhost:12345"), max_capacity: 100)
|
||||||
|
@ -32,7 +32,7 @@ module Invidious::ConnectionPool
|
|||||||
# Streaming API for {{method.id.upcase}} request.
|
# Streaming API for {{method.id.upcase}} request.
|
||||||
# The response will have its body as an `IO` accessed via `HTTP::Client::Response#body_io`.
|
# The response will have its body as an `IO` accessed via `HTTP::Client::Response#body_io`.
|
||||||
def {{method.id}}(*args, **kwargs, &)
|
def {{method.id}}(*args, **kwargs, &)
|
||||||
self.client do | client |
|
self.checkout do | client |
|
||||||
client.{{method.id}}(*args, **kwargs) do | response |
|
client.{{method.id}}(*args, **kwargs) do | response |
|
||||||
|
|
||||||
result = yield response
|
result = yield response
|
||||||
@ -47,14 +47,14 @@ module Invidious::ConnectionPool
|
|||||||
# Executes a {{method.id.upcase}} request.
|
# Executes a {{method.id.upcase}} request.
|
||||||
# The response will have its body as a `String`, accessed via `HTTP::Client::Response#body`.
|
# The response will have its body as a `String`, accessed via `HTTP::Client::Response#body`.
|
||||||
def {{method.id}}(*args, **kwargs)
|
def {{method.id}}(*args, **kwargs)
|
||||||
self.client do | client |
|
self.checkout do | client |
|
||||||
return client.{{method.id}}(*args, **kwargs)
|
return client.{{method.id}}(*args, **kwargs)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
# Checks out a client in the pool
|
# Checks out a client in the pool
|
||||||
private def client(&)
|
def checkout(&)
|
||||||
# If a client has been deleted from the pool
|
# If a client has been deleted from the pool
|
||||||
# we won't try to release it
|
# we won't try to release it
|
||||||
client_exists_in_pool = true
|
client_exists_in_pool = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user