Created
February 22, 2020 01:44
-
-
Save ioquatix/5e0877ab735ada54746f9f284f068e66 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'async' | |
require 'async/http/internet' | |
Async do |task| | |
internet = Async::HTTP::Internet.new | |
# Effectively a connection timeout: | |
response = task.with_timeout(10) do | |
internet.get("https://www.google.com/search?q=things") | |
end | |
# Effectively a read timeout: | |
task.with_timeout(1) do |timer| | |
while chunk = response.read | |
timer.reset | |
# Process chunk. | |
puts chunk.inspect | |
end | |
end | |
ensure | |
internet.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something like this?