NAME

Mojo::IOLoop::Trigger - IOLoop trigger

SYNOPSIS

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;

DESCRIPTION

Mojo::IOLoop::Trigger is a remote control for Mojo::IOLoop. Note that this module is EXPERIMENTAL and might change without warning!

EVENTS

Mojo::IOLoop::Trigger can emit the following events.

finish

$trigger->on(finish => sub {
  my $trigger = shift;
});

Emitted once the active event counter reaches zero.

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::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 finish event that stops it again once the active event counter reaches zero.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicio.us.