Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zeeshanlakhani
Forked from yob/gist:967934
Created January 13, 2012 06:14
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 zeeshanlakhani/1604879 to your computer and use it in GitHub Desktop.
Save zeeshanlakhani/1604879 to your computer and use it in GitHub Desktop.
Testing the combination of Async Sinatra with Em::HttpRequest
require 'rack'
require 'sinatra'
require 'sinatra/async'
require 'em-http-request'
# Trying out sinatra in async request mode.
#
# Run it like so:
#
# thin -R test.rb -p 4000 start
#
# Test it like so:
#
# ab -n 10 -c 10 http://127.0.0.1:4000/twitter.json
#
class Test < Sinatra::Base
# DNS queries aren't async on my system for some reason, so avoid them
TWITTER_HOST = "199.59.148.83"
register Sinatra::Async
aget '/' do
body "hello async"
end
aget '/twitter.json' do
http = EM::HttpRequest.new("http://#{TWITTER_HOST}/statuses/public_timeline.json").get
http.errback {
body {
"oh oh, error"
}
}
http.callback {
body {
http.response
}
}
end
end
Test.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment