Skip to content

Instantly share code, notes, and snippets.

@jordansissel
Created November 29, 2010 22:09
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 jordansissel/720723 to your computer and use it in GitHub Desktop.
Save jordansissel/720723 to your computer and use it in GitHub Desktop.
async_sinatra example using additional eventmachine calls
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)
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
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