The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

MojoX::IOLoop::Throttle - throttle Mojo events

VERSION

Version 0.01_06. (DEV)

SYNOPSIS

    use Mojo::Base -strict;
    use  MojoX::IOLoop::Throttle;
    $|=1;
    
    # New throttle object
    my $throttle = MojoX::IOLoop::Throttle->new();    
    
    # Subscribe to finish event
    $throttle->on(finish => sub { say "All done! Bye-bye"; });
    
    # Throttle!
    $throttle->throttle(
      limit => 20,                  # Play [limit] jobs(callbacks)
      limit_run => 3,               # But allow not more than [limit_run] running (parallel,incomplete) jobs
    
      period       => 2,            # seconds
      limit_period => 4,            # do not start more than [limit_period] jobs per [period] seconds 
    
      delay => 0.05,                # simulate (or not) a little latency between shots (timer resolution)
      cb => sub {
        my ($thr) = @_;
        my $rand_time = rand() / 5;
        say "Job $rand_time started";
        $thr->ioloop->timer($rand_time => sub {          
          say "job $rand_time ended";
          
          # Say that we end (to decrease limit_run count and let other job to start)
          $thr->end();
          });
      }
    );
    
    # Let's start
    $throttle->wait unless $throttle->ioloop->is_running;
    
    exit 0;;

DESCRIPTION

  AHTUNG!!!

  This is a very first development release. Be patient. Documentation is in progress.
  You can find some working real-life examples in 'example' dir.
  
  If your are going to use this module now, use subclassing, because all method and options are experimental

FUNCTIONS

end

in progress

wait

in progress

throttle

in progress

drop

in progress

AUTHOR

Alex, <alexbyk at cpan.org>

BUGS

Please report any bugs or feature requests to bug-mojox-ioloop-throttle at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MojoX-IOLoop-Throttle. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc MojoX::IOLoop::Throttle

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2012 Alex.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.