Created
June 9, 2015 13:39
-
-
Save AllanCochrane/1dd34f0fd3649ece7689 to your computer and use it in GitHub Desktop.
Mojolicious lite app for callback discussion
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 | |
use Mojolicious::Lite; | |
get '/' => sub { | |
my $c = shift; | |
$c->write("begin\n"); | |
my $i = int($c->param('i')); | |
my $cb; | |
$cb = sub { | |
$c->write("cb: $i\n", $i-- == 0 ? undef : $cb); | |
}; | |
$c->$cb(); | |
$c->write("end\n"); | |
}; | |
app->start; | |
# Output: | |
# begin | |
# cb: 10 | |
# end | |
# cb: 9 | |
# cb: 8 | |
# cb: 7 | |
# cb: 6 | |
# cb: 5 | |
# cb: 4 | |
# cb: 3 | |
# cb: 2 | |
# cb: 1 | |
# cb: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Invoke with
perl test1.pl get '/?i=10'