AnyEvent-Collect
view release on metacpan or search on metacpan
lib/AnyEvent/Collect.pm view on Meta::CPAN
version 0.1.0
=head1 SYNOPSIS
use AnyEvent;
use AnyEvent::Collect;
# Wait for all of a collection of events to trigger once:
my( $w1, $w2 );
collect {
$w1 = AE::timer 2, 0, event { say "two" };
$w2 = AE::timer 3, 0, event { say "three" };
}; # Returns after 3 seconds having printed "two" and "three"
# Wait for any of a collection of events to trigger:
my( $w3, $w4 );
collect_any {
$w3 = AE::timer 2, 0, event { say "two" };
$w4 = AE::timer 3, 0, event { say "three" };
};
# Returns after 2 seconds, having printed 2. Note however that
# the other event will still be emitted in another second. If
# you were to then execute the sleep below, it would print three.
# Or using L<ONE>
use ONE::Timer;
use AnyEvent::Collect;
collect {
ONE::Timer->after( 2 => event { say "two" } );
ONE::Timer->after( 3 => event { say "three" } );
}; # As above, returns after three seconds having printed "two" and
# "three"
# And because L<ONE> is based on L<MooseX::Event> and L<MooseX::Event>
# is integrated with L<Event::Wrappable>, you can just pass in raw subs
# rather then using the event helper:
collect_any {
ONE::Timer->after( 2 => sub { say "two" } );
ONE::Timer->after( 3 => sub { say "three" } );
}; # Returns after 2 seconds having printed "two"
=head1 DESCRIPTION
This allows you to reduce a group of unrelated events into a single event.
Either when the first event is emitted, or after all events have been
emitted at least once.
For your convenience this re-exports the event helper from
L<Event::Wrappable>. Only event listeners created with it or via a class
( run in 1.074 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )