Created
July 3, 2016 00:04
-
-
Save brianmed/63b06735d724e9894d52c18ce3a1b8b6 to your computer and use it in GitHub Desktop.
Recurring Mojo::IOLoop event with Mojo::IOLoop::ForkCall
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
use Mojo::Base -strict; | |
use Mojo::IOLoop::ForkCall; | |
my $fc = Mojo::IOLoop::ForkCall->new; | |
Mojo::IOLoop->recurring(1 => sub { | |
say(sprintf("%s: %s", scalar(localtime), "Ping")); | |
}); | |
Mojo::IOLoop->recurring(5 => sub { | |
$fc->run( | |
sub { sleep 5; return [ 1, `date` ] }, | |
sub { | |
my ($fc, $err, $ret) = @_; | |
$ret = $ret->[0]; | |
say("Got: $ret"); | |
} | |
); | |
}); | |
Mojo::IOLoop->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment