Created
February 23, 2012 17:23
-
-
Save hiroaki/1893896 to your computer and use it in GitHub Desktop.
A sample of streaming by Mojolicious
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
=pod | |
A sample of streaming. | |
This sends dynamic contents on "Transfer-Encoding: chunked". | |
See also the source: t/mojolicious/longpolling_lite_app.t | |
=cut | |
use Mojolicious::Lite; | |
get '/' => sub { | |
my $c = shift; | |
my $i = 0; | |
my $drain; | |
$drain = sub { | |
my $me = shift; | |
return $me->finish if( $i >= 10 ); | |
sleep 1; | |
my $chunk = sprintf '%d', $i++; | |
$me->write_chunk($chunk, $drain); | |
}; | |
$c->$drain; | |
}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment