-
-
Save anonymous/fac672eb7bc967b779da to your computer and use it in GitHub Desktop.
Mojolicious write_chunk testcase
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
package Testcase::Example; | |
use Mojo::Base 'Mojolicious::Controller'; | |
use Time::HiRes qw(sleep); | |
# This action will render a template | |
sub welcome { | |
my $self = shift; | |
$self->render_later; | |
$self->res->code(200); | |
$self->res->headers->content_type('text/plain'); | |
my $next_input; | |
my $n = 0; | |
$next_input = sub { | |
if($n == 150) { | |
return $self->write_chunk(''); | |
} | |
$n++; | |
sleep 0.1; | |
$self->write_chunk(">> $n <<\n", $next_input); | |
}; | |
$self->write_chunk("Begin of input!\n", $next_input); | |
} | |
1; |
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
package Testcase; | |
use Mojo::Base 'Mojolicious'; | |
# This method will run once at server start | |
sub startup { | |
my $self = shift; | |
# Routes | |
my $r = $self->routes; | |
$r->route('/')->to('example#welcome'); | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment