httprb / http

HTTP (The Gem! a.k.a. http.rb) - a fast Ruby HTTP client with a chainable API, streaming support, and timeouts
MIT License
3.01k stars 321 forks source link

[Feature] Ruby 3 Ractor support? #644

Open zt2 opened 3 years ago

zt2 commented 3 years ago

Ruby 3 support Ractor to archive concurrency, Ractor can not access instance variables of classes/modules.

When I want to use Ractor with http, I found http is using access instance variables of classes, for example:

require 'http'

ractors = []
url = 'http://httpbin.org/ip'
10.times do
  ractors << Ractor.new(url) { |u| HTTP.get u }
end
ractors.map(&:take)

This snippet will raise error http-4.4.1/lib/http/chainable.rb:221:in 'default_options': can not access instance variables of classes/modules from non-main Ractors (Ractor::IsolationError), because http using default_options as class instance variable.

Is it possible to make it support Ractor?