Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding an example of asynchronous requests.

  • Loading branch information...
commit 74afcc2fb586450f83658ec0523ffba500c83453 1 parent e093e94
@augustl authored
Showing with 13 additions and 0 deletions.
  1. +13 −0 asynchronous.rb
View
13 asynchronous.rb
@@ -0,0 +1,13 @@
+# All the APIs in Net::HTTP are synchronous.
+# We have to use threads.
+
+require "net/http"
+require "uri"
+
+Thread.new do
+ # Do normal Net::HTTP stuff here.
+ uri = URI.parse("http://google.com/")
+ http = Net::HTTP.new(uri.host, uri.port)
+ response = http.request(Net::HTTP::Get.new(uri.request_uri))
+end.join
+
Please sign in to comment.
Something went wrong with that request. Please try again.