Skip to content

Instantly share code, notes, and snippets.

@brianmed
Created June 21, 2016 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brianmed/9aa9ff6da65e17fd0e32178b26d7a8ff to your computer and use it in GitHub Desktop.
Save brianmed/9aa9ff6da65e17fd0e32178b26d7a8ff to your computer and use it in GitHub Desktop.
use Mojo::Base -strict;
use Mojo::IOLoop;
Mojo::IOLoop->timer(3.3 => sub {
say ("Worked!!");
});
Mojo::IOLoop->delay(
# First step (simple timer)
sub {
my $delay = shift;
Mojo::IOLoop->timer(2 => $delay->begin);
say 'Second step in 2 seconds.';
},
# Second step (concurrent timers)
sub {
my $delay = shift;
Mojo::IOLoop->timer(1 => $delay->begin);
Mojo::IOLoop->timer(3 => $delay->begin);
say 'Third step in 3 seconds.';
},
# Third step (the end)
sub { say 'And done after 5 seconds total.' }
)->wait;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment