No description, website, or topics provided.
Perl
Switch branches/tags
Nothing to show
Pull request Compare This branch is 17 commits behind tokuhirom:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib/Sub
t
xt
.gitignore
.shipit
Changes
MANIFEST
MANIFEST.SKIP
Makefile.PL
README
README.pod

README.pod

NAME

Sub::Retry - retry $n times

SYNOPSIS

use Sub::Retry;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new();
my $res = retry 3, 1, sub {
    $ua->post('http://example.com/api/foo/bar');
};

DESCRIPTION

Sub::Retry provides the function named 'retry'.

FUNCTIONS

retry($n_times, $delay, \&code [, \&retry_if])

This function calls \&code. If the code throws exception, this function retry $n_times after $delay seconds.

Return value of this function is the return value of \&code. This function cares wantarray.

You can also customize the retry condition. In that case \&retry_if specify coderef. The coderef arguments is return value the same. (Default: retry condition is throws exception)

use Sub::Retry;
use Cache::Memcached::Fast;

my $cache = Cache::Memcached::Fast->new(...);
my $res = retry 3, 1, sub {
    $cache->get('foo');
} sub {
    my $res = shift;
    defined $res ? 0 : 1;
};

AUTHOR

Tokuhiro Matsuno <tokuhirom AAJKLFJEF GMAIL COM>

LICENSE

Copyright (C) Tokuhiro Matsuno

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