Skip to content

Instantly share code, notes, and snippets.

@troelskn
Forked from rbarfoed/gist:4336511
Created December 19, 2012 13:15
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 troelskn/4336581 to your computer and use it in GitHub Desktop.
Save troelskn/4336581 to your computer and use it in GitHub Desktop.
require 'sinatra/base'
require 'eventmachine'
require 'em-http-request'
EM.run do
class App < Sinatra::Base
helpers do
def wait_for(&block)
while block.call.nil?
sleep(1.0 / 10)
end
end
end
get "/bar" do
response = nil
http = EventMachine::HttpRequest.new('https://www.google.dk/').get
http.callback {
response = http.response
}
wait_for { response }
content_type :json
[200, response.to_json]
end
end
App.run!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment