Skip to content

Instantly share code, notes, and snippets.

@brianmed
Created July 3, 2016 00:04
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 brianmed/63b06735d724e9894d52c18ce3a1b8b6 to your computer and use it in GitHub Desktop.
Save brianmed/63b06735d724e9894d52c18ce3a1b8b6 to your computer and use it in GitHub Desktop.
Recurring Mojo::IOLoop event with Mojo::IOLoop::ForkCall
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