Guest User

Untitled

a guest
Jan 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. require "rubygems"
  2. require "sinatra/base"
  3. require "sinatra/async"
  4. require "redis"
  5.  
  6. module CometTest
  7. class App < Sinatra::Base
  8. register Sinatra::Async
  9. puts ">> #{REDIS = Redis.new(:thread_safe => true)}"
  10.  
  11. aget "/get/:key" do |key|
  12. n = 0
  13. timer = EM::PeriodicTimer.new(0) do
  14. puts "checking #{key}"
  15.  
  16. val = REDIS.brpop key, 1
  17.  
  18. puts val.inspect
  19.  
  20. timer.cancel and body val.inspect.to_s if val
  21. timer.cancel and body "timeout" if (n+=1) > 25
  22. end
  23. end
  24. end
  25. end
  26.  
  27. puts "DONE"
Add Comment
Please, Sign In to add comment