Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to keep a persistent connection between requests #4

Open
mackuba opened this issue Dec 31, 2024 · 0 comments
Open

Add a way to keep a persistent connection between requests #4

mackuba opened this issue Dec 31, 2024 · 0 comments

Comments

@mackuba
Copy link
Owner

mackuba commented Dec 31, 2024

If you're making a lot of requests, it makes sense to open one HTTP connection and reuse it for many requests. In net/http, one connection is reused if you call Net::HTTP.start with a block and make multiple requests inside that block, or if you create an instance using Net::HTTP.new.

I need to think about how the API for this should look, but for now I'm locally testing something like this:

class Minisky
  attr_accessor :http_connection

  def make_request(request)
    response = @http_connection.request(request)
  end
end

api = Minisky.new('public.api.bsky.app', nil)

Net::HTTP.start('public.api.bsky.app', 443, use_ssl: true) do |http|
  api.http_connection = http

  ... api.fetch_all ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant