Last active
September 10, 2016 07:39
-
-
Save ggl/96748aed5e88e37c13598c5cbe5fe85d to your computer and use it in GitHub Desktop.
Tell the time using a recurring Mojo::IOLoop timer
This file contains hidden or 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 Mojo::IOLoop; | |
use POSIX; | |
# Start at sec % 5 == 0 | |
Mojo::IOLoop->timer((5 - (localtime)[0] % 5) => sub { | |
# Perform operation every 5 seconds | |
Mojo::IOLoop->recurring(5 => sub { | |
my $loop = shift; | |
print "The time is ".POSIX::strftime("%F %T %Z", localtime())."\n"; | |
}); | |
}); | |
# Start event loop if necessary | |
Mojo::IOLoop->start unless Mojo::IOLoop->is_running; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment