Skip to content

Instantly share code, notes, and snippets.

@ericboehs
Created January 30, 2023 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericboehs/4dcca8f5d73872d903811af41e729568 to your computer and use it in GitHub Desktop.
Save ericboehs/4dcca8f5d73872d903811af41e729568 to your computer and use it in GitHub Desktop.
Ruby Read Timeout vs Global
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!'
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
@ericboehs
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment