Skip to content

Instantly share code, notes, and snippets.

@renormalist
Created July 4, 2019 12:22
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 renormalist/9146666907fdeeb62cd1d649db52bd3e to your computer and use it in GitHub Desktop.
Save renormalist/9146666907fdeeb62cd1d649db52bd3e to your computer and use it in GitHub Desktop.
Mojo deep recursion
#! /usr/bin/env perl
use 5.022;
use strict;
use warnings;
use Mojolicious::Lite;
use Time::HiRes 'usleep';
# global, used in event subs, is that ok?
my $loop = Mojo::IOLoop->new;
sub workload {
my $counter = 0;
while ($counter < 100) {
usleep (100);
$counter++;
}
$loop->emit('check_queue');
}
sub check_queue {
$loop->emit('workload');
}
$loop->on(workload => \&workload);
$loop->on(check_queue => \&check_queue);
$loop->recurring(1 => \&check_queue);
$loop->start unless $loop->is_running;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment