Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tokuhirom/sub-retry
https://github.com/tokuhirom/sub-retry
Last synced: 18 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/tokuhirom/sub-retry
- Owner: tokuhirom
- License: other
- Created: 2011-01-13T11:37:35.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2024-03-19T03:42:04.000Z (8 months ago)
- Last Synced: 2024-10-11T20:57:31.833Z (about 1 month ago)
- Language: Perl
- Homepage:
- Size: 32.2 KB
- Stars: 11
- Watchers: 4
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
- License: LICENSE
Awesome Lists containing this project
README
# NAME
Sub::Retry - retry $n times
# SYNOPSIS
use Sub::Retry;
use LWP::UserAgent;my $ua = LWP::UserAgent->new();
my $res = retry 3, 1, sub {
my $n = shift;
$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](http://search.cpan.org/perldoc?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
# 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.