Rainbows! Rack HTTP server user/dev discussion
 help / color / mirror / code / Atom feed
* Long Polling
@ 2009-12-07 16:40 Alexander
       [not found] ` <fc2a0ebf0912070840r5ffec0d2r5eb72419ae810f21-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander @ 2009-12-07 16:40 UTC (permalink / raw)
  To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw

Please, could anybody explain how to create simple long polling app
with rainbows?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Long Polling
       [not found] ` <fc2a0ebf0912070840r5ffec0d2r5eb72419ae810f21-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2009-12-07 20:02   ` Eric Wong
       [not found]     ` <20091207200234.GA26894-yBiyF41qdooeIZ0/mPfg9Q@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Wong @ 2009-12-07 20:02 UTC (permalink / raw)
  To: Rainbows! list

Alexander <insinium-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org
http://rubyforge.org/mailman/listinfo/rainbows-talk
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Long Polling
       [not found]     ` <20091207200234.GA26894-yBiyF41qdooeIZ0/mPfg9Q@public.gmane.org>
@ 2009-12-08 14:26       ` Alexander
  0 siblings, 0 replies; 3+ messages in thread
From: Alexander @ 2009-12-08 14:26 UTC (permalink / raw)
  To: Rainbows! list

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 = []
  end

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

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

end

run LongPollingServlet.new


Thanks for explains,
YR,
Alexander.

2009/12/7 Eric Wong <normalperson-rMlxZR9MS24@public.gmane.org>
>
> Alexander <insinium-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org
> http://rubyforge.org/mailman/listinfo/rainbows-talk
> Do not quote signatures (like this one) or top post when replying
_______________________________________________
Rainbows! mailing list - rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org
http://rubyforge.org/mailman/listinfo/rainbows-talk
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-12-08 14:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-07 16:40 Long Polling Alexander
     [not found] ` <fc2a0ebf0912070840r5ffec0d2r5eb72419ae810f21-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-12-07 20:02   ` Eric Wong
     [not found]     ` <20091207200234.GA26894-yBiyF41qdooeIZ0/mPfg9Q@public.gmane.org>
2009-12-08 14:26       ` Alexander

Code repositories for project(s) associated with this inbox:

	../../../rainbows.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).