Mojo::IOLoop::Trigger - IOLoop trigger
use Mojo::IOLoop::Trigger; # Synchronize multiple events my $t = Mojo::IOLoop::Trigger->new; $t->on(finish => sub { say 'BOOM!' }); for my $i (1 .. 10) { $t->begin; Mojo::IOLoop->timer($i => sub { say 10 - $i; $t->end; }); } # Stop automatically when finished $t->start;
Mojo::IOLoop::Trigger is a remote control for Mojo::IOLoop. Note that this module is EXPERIMENTAL and might change without warning!
Mojo::IOLoop::Trigger can emit the following events.
finish
$trigger->on(finish => sub { my $trigger = shift; });
Emitted once the active event counter reaches zero.
Mojo::IOLoop::Trigger implements the following attributes.
ioloop
my $ioloop = $t->ioloop; $t = $t->ioloop(Mojo::IOLoop->new);
Loop object to control, defaults to a Mojo::IOLoop object.
Mojo::IOLoop::Trigger inherits all methods from Mojo::EventEmitter and implements the following new ones.
begin
my $cb = $t->begin;
Increment active event counter, the returned callback can be used instead of end.
end
my $t = Mojo::IOLoop->trigger; Mojo::IOLoop->resolver->lookup('mojolicio.us' => $t->begin); my $address = $t->start;
$t->end; $t->end(@args);
Decrement active event counter.
start
my @args = $t->start;
Start ioloop and register finish event that stops it again once the active event counter reaches zero.
Mojolicious, Mojolicious::Guides, http://mojolicio.us.
To install Mojolicious, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious
CPAN shell
perl -MCPAN -e shell install Mojolicious
For more information on module installation, please visit the detailed CPAN module installation guide.