Created
July 4, 2019 12:22
-
-
Save renormalist/9146666907fdeeb62cd1d649db52bd3e to your computer and use it in GitHub Desktop.
Mojo deep recursion
This file contains 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 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