Created
November 29, 2010 22:09
-
-
Save jordansissel/720723 to your computer and use it in GitHub Desktop.
async_sinatra example using additional eventmachine calls
This file contains 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
require "rubygems" | |
require "sinatra/async" | |
require "rack" | |
class Foo < Sinatra::Base | |
register Sinatra::Async | |
aget "/foo" do | |
EM::add_timer(1) do | |
headers "Content-Type" => "text/plain" | |
body "Async hello!\n" | |
end | |
end | |
end | |
Rack::Handler::Thin.run(Foo.new) |
This file contains 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
snack(~) % ruby as.rb | |
>> Thin web server (v1.2.7 codename No Hup) | |
>> Maximum connections set to 1024 | |
>> Listening on 0.0.0.0:8080, CTRL+C to stop |
This file contains 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
snack(~) % time curl localhost:8080/foo | |
Async hello! | |
curl localhost:8080/foo 0.00s user 0.01s system 0% cpu 1.102 total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment