DISQUS

The Cappuccino Blog: Push with Cappuccino and Tornado

  • Johannes Fahrenkrug · 2 months ago
    Very cool, Elias!
  • pabloponsbordes · 2 months ago
    This is amazing, congratulation for your work it looks really great.
    I will make some experiment with it.
  • Luca Bonifazi · 2 months ago
    I've tried async_sinatra on a rails metal class instead of Tornado and without juggernaut.
    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
  • Luca Bonifazi · 2 months ago
    It needs thin for async.
    script/server thin