AnyEvent-Retry

 view release on metacpan or  search on metacpan

lib/AnyEvent/Retry/Coro.pm  view on Meta::CPAN

    $self->running_coro(async {
        $self->handle_result($self->run_code);
        $self->clear_running_coro if defined $self;
    });
};

sub DEMOLISH {
    my $self = shift;
    $self->running_coro->throw('DEMOLISH');
}

sub wait {
    my ($status, @args) = Coro::rouse_wait();
    return $args[0] if $status eq 'success';
    die $args[1];
}

sub run {
    my $self = shift;
    $self->start;

    # this is so DEMOLISH still works right
    my $class = $self->meta->name;
    undef $self;
    $class->wait;
}

__PACKAGE__->meta->make_immutable;



=pod

=head1 NAME

AnyEvent::Retry::Coro - AnyEvent::Retry for jobs that run in separate threads

=head1 VERSION

version 0.03

=head1 SYNOPSIS

    use Coro;

    my $r = AnyEvent::Retry::Coro->new(
        max_tries => 100, # eventually give up
        interval  => { Constant => { interval => 1 } }, # try every second
        try       => {
            die 'out of cake!' if $cake-- < 0;
            return do_science();
        },

    );

    my $neat_gun = $r->run; # keep on trying until you run out of cake

=head1 DESCRIPTION

This module makes L<AnyEvent::Retry> work nicely with L<Coro>.  You
don't need to provide success or failure callbacks anymore, and your
task to retry just needs C<die> or return a result.

=head1 METHODS

=head2 run

This runs the task, blocking the thread until a result is available.
If your task encounters an error, this will die.  If it's sucessful,
it returns the result.

=head2 wait

Allows you to run the task without blocking:

    $r->start;
    ...; # do anything
    my $result = $r->wait; # block here

C<run> is implemented exactly like the above.

=head1 AUTHOR

Jonathan Rockway <jrockway@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Jonathan Rockway.

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

=cut


__END__



( run in 3.403 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )