socketry / async-http

MIT License
309 stars 45 forks source link

`Async::HTTP::Client#get` with a block does not appear to yield a response #170

Open postmodern opened 1 month ago

postmodern commented 1 month ago

I'm attempting to call Async::HTTP::Client#get with a block, but the block never seems to execute?

Steps To Reproduce

require 'bundler/setup'
require 'async/http'
require 'json'

endpoint = Async::HTTP::Endpoint.for('https','example.com')
client   = Async::HTTP::Client.new(endpoint)

Async do
  client.get('/') do |response|
    puts "got here"
    puts response.read
  end
end

Expected Result

got here
...

Actual Result

 0.09s     warn: Async::Pool::Controller: Async::Pool::Controller Gardener [oid=0x67c] [ec=0x690] [pid=25251] [2024-07-26 21:28:18 -0700]
               | Closing resource while still in use!
               | {
               |   "resource": "#<Async::HTTP::Protocol::HTTP2::Client 1 requests, 0 active streams>",
               |   "usage": 1
               | }

Versions

ioquatix commented 1 month ago

That's the current behaviour, the yield with response behaviour only applies to Async::HTTP::Internet as it's a higher level construct. I understand how this might be confusing, but Client is quite complex already and I'm not sure there is huge value in propagating the "convenient" interface lower. I'll certainly think about it though.

https://github.com/socketry/async-http/blob/main/lib/async/http/internet.rb#L42-L60