Last active
December 19, 2015 14:59
-
-
Save ian-kent/5973234 to your computer and use it in GitHub Desktop.
Mojolicious route blocking further calls to itself
This file contains hidden or 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 EventTest; | |
use Mojo::Base 'Mojolicious'; | |
#use EV; | |
use AnyEvent; | |
# Call /wait1 and /wait2, both block but both get handled asynchronously | |
# Call /wait1 and another /wait1, the first request blocks the second | |
# Regardless of above, calling /nowait always works | |
sub startup { | |
my $self = shift; | |
my $r = $self->routes; | |
$r->get('/wait1')->to(cb => sub { | |
my $self = shift; | |
print "BEGIN WAIT 1\n"; | |
my $w; | |
$w = AE::timer 5, 0, sub { | |
$self->render(text => "Wait 1 response"); | |
undef $w; | |
print "END WAIT 1\n"; | |
} | |
}); | |
$r->get('/wait2')->to(cb => sub { | |
my $self = shift; | |
print "BEGIN WAIT 2\n"; | |
my $w; | |
$w = AE::timer 5, 0, sub { | |
$self->render(text => "Wait 2 response"); | |
undef $w; | |
print "END WAIT 2\n"; | |
} | |
}); | |
$r->get('/nowait')->to(cb => sub { | |
print "BEGIN NOWAIT\n"; | |
shift->render(text => "Nowait response"); | |
print "END NOWAIT\n"; | |
}); | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment