Skip to content

Instantly share code, notes, and snippets.

@hukl
Created September 4, 2010 21:00
Show Gist options
  • Save hukl/565487 to your computer and use it in GitHub Desktop.
Save hukl/565487 to your computer and use it in GitHub Desktop.
require 'async_sinatra'
class App < Sinatra::Base
register Sinatra::Async
aget '/' do
timed_out = false
timeout = EM::Timer.new(7) do
timed_out = true
body { '{"state": "not_found"}' }
end
completion = lambda do |result|
timeout.cancel
body { result } unless timed_out
end
work = lambda do
# do something here to calculate result
result
end
EM.defer(work, completion)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment