Long Polling

Alexander insinium at gmail.com
Tue Dec 8 09:26:50 EST 2009

Hello Eric!
Thank You very much!
After some unsuccessful attempt to construct it,
I mean, that finaly, a got worked class.

So, if intresting, you can look it

require 'sinatra/async'

class LongPollingServlet < Sinatra::Base
  register Sinatra::Async

  enable :show_exceptions

  def initialize
    @queue = []

  aget '/' do
    @queue << EM.Callback { |message| body message }

  get '/pull/:message' do |message|
    obj = @queue.shift
    obj.call message if obj


run LongPollingServlet.new

Thanks for explains,

2009/12/7 Eric Wong <normalperson at yhbt.net>
> Alexander <insinium at gmail.com> wrote:
> > Please, could anybody explain how to create simple long polling app
> > with rainbows?
> Hi Alexander,
> I'm not sure if anybody has actually written one for Rainbows!, but I
> think they usually include sleeping or using async.callback like
> async_sinatra[1].
> For the concurrency models that appear synchronous, you can check out
> t/sleep.ru in the test cases for sleep examples:
>  (case env['rainbows.model']
>  when :FiberPool, :FiberSpawn
>    Rainbows::Fiber
>  when :Revactor
>    Actor
>  else # :ThreadPool, :ThreadSpawn
>    Kernel
>  end).sleep(nr)
> I may put that logic into a env["async.sleep"] callback in places where
> env["async.callback"] is not available so the synchronous-looking
> concurrency models can all share the same code.
> If you're using EventMachine, NeverBlock (and in future versions: Rev,
> RevThreadSpawn, RevThreadPool, EventMachineDefer,
> EventMachineThreadSpawn), you can use "async.callback" or just use
> async_synatra which uses "async.callback" internally.
> [1] http://github.com/raggi/async_sinatra
> --
> Eric Wong
> _______________________________________________
> Rainbows! mailing list - rainbows-talk at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rainbows-talk
> Do not quote signatures (like this one) or top post when replying

More information about the rainbows-talk mailing list