Skip to content

Instantly share code, notes, and snippets.

@ian-kent
Last active December 19, 2015 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ian-kent/5973234 to your computer and use it in GitHub Desktop.
Save ian-kent/5973234 to your computer and use it in GitHub Desktop.
Mojolicious route blocking further calls to itself
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