rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
* streaming api
@ 2010-02-03  4:47 Dominic Sisneros
  2010-02-03 10:59 ` Eric Wong
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Dominic Sisneros @ 2010-02-03  4:47 UTC (permalink / raw)
  To: rack-devel

[-- Attachment #1: Type: text/plain, Size: 1484 bytes --]

The perl folks jumped on the rack & wsgi trend in a big way with psgi and
are doing a lot of interesting stuff.

One of the things that they have done differently is have an optional
streaming interface.

http://bulknews.typepad.com/blog/2009/10/psgiplack-streaming-is-now-complete.html

So, basically the idea is the same as the original Python WSGI's
start_response but this callback is NOT an optional parameter to the app
because that stands in the way of everybody in the chain including
middleware and that sucks. Instead, an app can optionally return a callback
that accepts another callback to which you can return the response array ref
(code, headers and body) if you want to delay your response.

my $app = sub {
  my $env = shift;
  return sub {
    my $respond = shift;
    # do some event stuff
    $event->callback(sub { $respod->([ $code, $headers, $body ]) });
  };
};

If you also want to delay the content body delivery as well (i.e. streaming)
you can omit the body, in which case you'll get the writer object that has
write(), close() and poll_cb().

my $app = sub {
  my $env = shift;
  return sub {
    my $respond = shift;
    my $w = $respond->([ 200, [ 'Content-Type' => 'text/plain' ]]); #
no $body here
    # do more event stuff
    $event->callback(sub { $w->write($body) });
    $event->done_callback(sub { $w->close });
  };
};


That post also has links to other posts about their streaming rack like
interface

Should rack pursue something like this?

[-- Attachment #2: Type: text/html, Size: 1783 bytes --]

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

end of thread, other threads:[~2010-02-04 16:34 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-03  4:47 streaming api Dominic Sisneros
2010-02-03 10:59 ` Eric Wong
2010-02-03 18:14   ` Randy Fischer
2010-02-04 10:32     ` James Tucker
2010-02-04 10:39     ` Eric Wong
2010-02-04 10:41       ` Eric Wong
2010-02-04 15:00         ` Tom Robinson
2010-02-04 16:34           ` James Tucker
2010-02-03 11:02 ` James Tucker
2010-02-03 18:08   ` Jeremy Hinegardner
2010-02-03 11:25 ` Tom Robinson

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).