Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Block till one or more events fire

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 t
Octocat-spinner-32 .gitignore
Octocat-spinner-32 ChangeLog
Octocat-spinner-32 README.pod
Octocat-spinner-32 dist.ini
Octocat-spinner-32 weaver.ini
README.pod

NAME

AnyEvent::Collect - Block till one or more events fire

VERSION

version 0.1.0

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"

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 Event::Wrappable. Only event listeners created with it or via a class that integrates with Event::Wrappable (eg, MooseX::Event) will be captured.

HELPERS

sub event( CodeRef $todo )

See Event::Wrappable for details.

sub collect( CodeRef $todo )

sub collect_all( CodeRef $todo )

Will return after all of the events declared inside the collect block have been emitted at least once.

sub collect_any( CodeRef $todo )

Will return after any of the events declared inside the collect block have been emitted at least once. Note that it doesn't actually cancel the unemitted events-- you'll have to do that yourself, if that's what you want.

SEE ALSO

SOURCE

The development version is on github at http://https://github.com/iarna/AnyEvent-Collect and may be cloned from git://https://github.com/iarna/AnyEvent-Collect.git

SUPPORT

Websites

More information can be found at:

Bugs / Feature Requests

Please report any bugs at https://github.com/iarna/AnyEvent-Collect/issues.

AUTHOR

Rebecca Turner <becca@referencethis.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Rebecca Turner.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

Something went wrong with that request. Please try again.