Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #! /usr/bin/env perl
  2.  
  3. use 5.022;
  4. use strict;
  5. use warnings;
  6.  
  7. use Mojolicious::Lite;
  8. use Time::HiRes 'usleep';
  9.  
  10. # global, used in event subs, is that ok?
  11. my $loop = Mojo::IOLoop->new;
  12.  
  13. sub workload {
  14. my $counter = 0;
  15. while ($counter < 100) {
  16. usleep (100);
  17. $counter++;
  18. }
  19. $loop->emit('check_queue');
  20. }
  21.  
  22. sub check_queue {
  23. $loop->emit('workload');
  24. }
  25.  
  26. $loop->on(workload => \&workload);
  27. $loop->on(check_queue => \&check_queue);
  28.  
  29. $loop->recurring(1 => \&check_queue);
  30.  
  31. $loop->start unless $loop->is_running;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement