Rainbows! Rack HTTP server user/dev discussion
 help / color / mirror / code / Atom feed
From: Alexander <insinium-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: "Rainbows! list" <rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org>
Subject: Re: Long Polling
Date: Tue, 8 Dec 2009 17:26:50 +0300	[thread overview]
Message-ID: <fc2a0ebf0912080626k759d0941h67541436e1723f34@mail.gmail.com> (raw)
In-Reply-To: <20091207200234.GA26894-yBiyF41qdooeIZ0/mPfg9Q@public.gmane.org>

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


      parent reply	other threads:[~2009-12-08 14:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/rainbows/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fc2a0ebf0912080626k759d0941h67541436e1723f34@mail.gmail.com \
    --to=insinium-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/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).