Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.