Skip to content

Instantly share code, notes, and snippets.

@aasmith
Created September 5, 2011 16:49
Show Gist options
  • Save aasmith/1195446 to your computer and use it in GitHub Desktop.
Save aasmith/1195446 to your computer and use it in GitHub Desktop.
async sinatra - comet
require "rubygems"
require "sinatra/base"
require "sinatra/async"
require "redis"
module CometTest
class App < Sinatra::Base
register Sinatra::Async
puts ">> #{REDIS = Redis.new(:thread_safe => true)}"
aget "/get/:key" do |key|
n = 0
timer = EM::PeriodicTimer.new(0) do
puts "checking #{key}"
val = REDIS.brpop key, 1
puts val.inspect
timer.cancel and body val.inspect.to_s if val
timer.cancel and body "timeout" if (n+=1) > 25
end
end
end
end
puts "DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment