NAME
Mojo::IOLoop::Trigger - IOLoop Trigger
SYNOPSIS
use Mojo::IOLoop::Trigger;
# Synchronize multiple events
my $t = Mojo::IOLoop::Trigger->new;
$t->on(done => sub { print "BOOM!\n" });
for my $i (1 .. 10) {
$t->begin;
Mojo::IOLoop->timer($i => sub {
print 10 - $i, "\n";
$t->end;
});
}
# Stop automatically when done
$t->start;
DESCRIPTION
Mojo::IOLoop::Trigger is a remote control for Mojo::IOLoop. Note that this module is EXPERIMENTAL and might change without warning!
ATTRIBUTES
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.
METHODS
Mojo::IOLoop::Trigger inherits all methods from Mojo::IOLoop::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
.
my $t = Mojo::IOLoop->trigger;
Mojo::IOLoop->resolver->lookup('mojolicio.us' => $t->begin);
my $address = $t->start;
end
$t->end;
$t->end(@args);
Decrement active event counter.
start
my @args = $t->start;
Start ioloop
and register done
event that stops it again once the active event counter reaches zero.
EVENTS
Mojo::IOLoop::Trigger can emit the following events.
done
Emitted once the active event counter reaches zero.