Created
September 4, 2010 21:00
-
-
Save hukl/565487 to your computer and use it in GitHub Desktop.
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 '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