Created
July 26, 2011 01:17
-
-
Save kraih/1105705 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
#!/usr/bin/env perl | |
use Mojolicious::Lite; | |
use EV; | |
use AnyEvent; | |
# Simple delayed rendering | |
get '/' => sub { | |
my $self = shift; | |
my $w; | |
$w = AE::timer 3, 0, sub { | |
$self->render_text('3 seconds delayed!'); | |
undef $w; | |
}; | |
}; | |
app->start; |
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; | |
use EV; | |
use AnyEvent; | |
# Naive timer | |
my $counter = 0; | |
my $w = AnyEvent->timer( | |
after => 1, | |
interval => 1, | |
cb => sub { say $counter++ } | |
); | |
# Normal route | |
get '/' => sub { | |
my $self = shift; | |
$self->render(text => "Counter: $counter"); | |
}; | |
app->start; |
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; | |
use EV; | |
use AnyEvent; | |
# Timer that survives prefork | |
my $counter = 0; | |
my $w; | |
under sub { | |
$w ||= AnyEvent->timer( | |
after => 1, | |
interval => 1, | |
cb => sub { say $counter++ } | |
); | |
}; | |
# Normal route | |
get '/' => sub { | |
my $self = shift; | |
$self->render(text => "Counter: $counter"); | |
}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment