28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/benchmark/http/command/wait.rb', line 28
def run(url, parent: Async::Task.current)
endpoint = Async::HTTP::Endpoint.parse(url)
request_path = endpoint.url.request_uri
maximum_wait = @options[:wait]
parent.async do
clock = Async::Clock.start
client = Async::HTTP::Client.new(endpoint)
begin
client.get(request_path).tap(&:finish)
rescue => error
if clock.total > maximum_wait
raise
else
sleep 0.01
retry
end
end
Console.logger.info(self) {"#{url} is ready after #{clock.total} seconds."}
ensure
client.close
end
end
|