Created
June 4, 2017 21:21
-
-
Save jberger/f5a8e9b6df0d68687411a07fec355e99 to your computer and use it in GitHub Desktop.
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
use Mojolicious::Lite; | |
any '/' => sub { | |
my $c = shift; | |
my $can_write = 1; | |
my $buffer = ''; | |
my $done; | |
# fake system that generates data every second | |
my $r; | |
$r = Mojo::IOLoop->recurring(1 => sub { | |
$buffer .= "Some new content\n" unless $done; | |
if ($can_write) { | |
$can_write = 0; | |
$c->write_chunk($buffer => sub { $can_write = 1 }); | |
$buffer = ''; | |
Mojo::IOLoop->remove($r) if $done; | |
} | |
}); | |
Mojo::IOLoop->timer(10 => sub { $done++ }); | |
}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment