Skip to content

Commit 7504b97

Browse files
committed
Rewrote library.
1 parent c34c68c commit 7504b97

File tree

14 files changed

+713
-342
lines changed

14 files changed

+713
-342
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
vendor
1+
/vendor/
2+
/.*/

.travis.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
notifications:
2+
email: false
3+
4+
sudo: false
5+
6+
language: php
7+
8+
php:
9+
- 5.5
10+
- 5.6
11+
- 7.0
12+
13+
install:
14+
- alias composer=composer\ -n && composer selfupdate
15+
- composer validate
16+
- composer --prefer-source install
17+
- composer --prefer-source require satooshi/php-coveralls
18+
19+
script:
20+
- bin/test --coverage-clover=build/logs/clover.xml
21+
22+
after_success:
23+
- vendor/bin/coveralls -v

CHANGELOG.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

LICENSE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Copyright (c) 2014 Igor Wiedler
1+
Copyright (c) Bilge 2016.
2+
Portions copyright (C) 2014 Igor Wiedler.
23

34
Permission is hereby granted, free of charge, to any person obtaining a copy
45
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,50 @@
1-
# retry
1+
Retry
2+
=====
23

3-
A tiny library for retrying failing operations.
4+
[![Latest version][Version image]][Releases]
5+
[![Build status][Build image]][Build]
6+
[![Test coverage][Coverage image]][Coverage]
7+
[![Code style][Style image]][Style]
48

5-
Since the network is reliable, things should always work. Am I right? For those cases when they don't, there is *retry*.
9+
Retry provides a function to retry failing operations. An operation is deemed to have failed if it throws an exception.
610

7-
```php
8-
<?
9-
use function igorw\retry;
11+
Requirements
12+
------------
1013

11-
// retry an operation up to 5 times
12-
$user = retry(5, function () use ($id) {
13-
return User::find($id);
14-
});
14+
- [PHP 5.5](http://php.net/)
15+
- [Composer](https://getcomposer.org/)
16+
17+
Usage
18+
-----
19+
20+
The `retry` function has the following signature.
21+
22+
```
23+
retry(int $times, callable $operation);
24+
```
25+
* `$times` specifies how many times the operation may be called.
26+
* `$operation` is a callback to be run up to the specified number of times.
27+
28+
Note that in the [original library](https://github.com/igorw/retry), `$times` specified the number of *retries* and therefore the operation could run up to `n + 1` times. In this version, `$times` specifies exactly the number of times the operation may run such that if zero (`0`) is specified it will never run.
29+
30+
### Example
1531

16-
// here is why you want to start using HHVM
17-
$user = retry(5, () ==> User::find($id));
32+
```php
33+
use function ScriptFUSION\Retry\retry;
1834

19-
// this is probably a bad idea
20-
$user = retry(INF, () ==> {
21-
throw new RuntimeException('never gonna give you up');
35+
// Try an operation up to 5 times.
36+
$response = retry(5, function () use ($url) {
37+
return HttpConnector::fetch($url);
2238
});
23-
?>
2439
```
2540

26-
I know. You're welcome.
41+
42+
[Releases]: https://github.com/ScriptFUSION/Retry/releases
43+
[Version image]: https://poser.pugx.org/scriptfusion/retry/v/stable "Latest version"
44+
[Build]: http://travis-ci.org/ScriptFUSION/Retry
45+
[Build image]: https://travis-ci.org/ScriptFUSION/Retry.svg "Build status"
46+
[Coverage]: https://coveralls.io/github/ScriptFUSION/Retry
47+
[Coverage image]: https://coveralls.io/repos/ScriptFUSION/Retry/badge.svg "Test coverage"
48+
[Style]: https://styleci.io/repos/62990558
49+
[Style image]: https://styleci.io/repos/62990558/shield?style=flat "Code style"
50+

bin/test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
cd "$(dirname "$0")"/..
4+
5+
vendor/bin/phpunit -c test "$@"

composer.json

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
{
2-
"name": "igorw/retry",
3-
"description": "A tiny library for retrying failing operations.",
4-
"keywords": ["failure"],
5-
"license": "MIT",
6-
"authors": [
7-
{
8-
"name": "Igor Wiedler",
9-
"email": "igor@wiedler.ch"
10-
}
11-
],
12-
"require": {
13-
"php": ">=5.4"
14-
},
15-
"require-dev": {
16-
"phpunit/phpunit": "~4.2"
17-
},
18-
"autoload": {
19-
"files": ["src/retry.php"]
2+
"name": "scriptfusion/retry",
3+
"description": "Retries failing operations.",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "Bilge",
8+
"email": "bilge@scriptfusion.com"
209
},
21-
"extra": {
22-
"branch-alias": { "dev-master": "1.0-dev" }
10+
{
11+
"name": "Igor Wiedler",
12+
"email": "igor@wiedler.ch"
13+
}
14+
],
15+
"require": {
16+
"php": "^5.5|^7"
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "^4"
20+
},
21+
"autoload": {
22+
"files": [
23+
"src/retry.php"
24+
],
25+
"psr-4": {
26+
"ScriptFUSION\\Retry\\": "src"
2327
}
28+
}
2429
}

0 commit comments

Comments
 (0)