Ruby Read Timeout vs Global
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
require 'net/http' | |
url = URI.parse 'http://localhost:9292/' | |
request = Net::HTTP::Get.new url.path | |
response = Net::HTTP.start(url.host, url.port) do |http| | |
http.read_timeout = 2 | |
http.request request | |
end | |
puts 'Timeout was not reached!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rack/handler/puma' | |
class App | |
def call(request) | |
delay = 1 # second | |
body = Enumerator.new do |enum| | |
5.times do |i| | |
puts "Sleeping #{delay}" | |
sleep delay | |
enum << "#{i}\n" | |
end | |
end | |
[200, { 'Content-Type' => 'application/json'}, body] | |
end | |
end | |
Rack::Handler::Puma.run App.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read timeouts aren't global timeouts.