Skip to content

Instantly share code, notes, and snippets.

@ggl
Last active September 10, 2016 07:39
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 ggl/96748aed5e88e37c13598c5cbe5fe85d to your computer and use it in GitHub Desktop.
Save ggl/96748aed5e88e37c13598c5cbe5fe85d to your computer and use it in GitHub Desktop.
Tell the time using a recurring Mojo::IOLoop timer
#!/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