-
Website
http://cappuccino.org/discuss -
Original page
http://cappuccino.org/discuss/2009/10/05/push-with-cappuccino-and-tornado/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
joeyguerra
2 comments · 1 points
-
boucher
35 comments · 7 points
-
milestinsley
2 comments · 2 points
-
Jules
1 comment · 1 points
-
pabloponsbordes
2 comments · 1 points
-
-
Popular Threads
I will make some experiment with it.
It worked, not well coded, just a proof of concept.
Some work to do on AppController.j for the cappuccino app, just json messages parsing and connection urls.
Here's the metal code
require 'sinatra/async'
#thread safe notificator
class Looper
include EM::Deferrable
def initialize
@waiters = EM::Queue.new
end
def add_listener(listener)
@waiters.push(listener)
end
def notify(x)
res = x.to_json
@waiters.size().times do
@waiters.pop{ |w|
w.body res
}
end
end
end
class SinatraTest < Sinatra::Base
register Sinatra::Async
enable :show_exceptions
@@df = Looper.new
@@df.callback {|x|
@@df.notify(x)
}
def self.restart_looper
@@df = Looper.new
@@df.callback {|x|
@@df.notify(x)
}
end
apost '/message' do
message={:type => params["type"],:sender => params["sender"],:body => params["body"]}
body ""
@@df.set_deferred_status :succeeded, message
SinatraTest.restart_looper
end
apost '/color' do
color = {:type => params["type"],:color => params["color"]}
body ""
@@df.set_deferred_status :succeeded, color
SinatraTest.restart_looper
end
apost '/updates' do
@@df.add_listener(self)
end
end
script/server thin