Fiber Concurrency

The :fiber_concurrency plugin enables connections in a session to be reused seamlessly across fibers managed by a fiber scheduler. This is of particular relevance if the connections are long-lived/persistent.

Note that, if you’re using the :persistent plugin, it’s required by default already.

How to use


http = HTTPX.plugin(:fiber_concurrency)

Thread.start do
  Fiber.set_scheduler(SmthScheduler)

  10.times.each do
    Fiber.schedule do
      # (HTTP/2) will open a new connection/socket for each of these requests
      HTTPX.get("https://example.com")
    end
  end

  10.times.each do
    Fiber.schedule do
      # (HTTP/2) will open a single connection and send all 10 requests in concurrent streams (HTTP/2)
      http.get("https://example.com")
    end
  end
end

Who is this for

This plugin is a requirement if you’re using httpx in programs with a fiber scheduler. This includes, for example, programs developed using the async gem.

Next: Custom Plugins