Skip to content

Commit

Permalink
Rewrote library.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Jul 10, 2016
1 parent c34c68c commit 7504b97
Show file tree
Hide file tree
Showing 14 changed files with 713 additions and 342 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
vendor
/vendor/
/.*/
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
notifications:
email: false

sudo: false

language: php

php:
- 5.5
- 5.6
- 7.0

install:
- alias composer=composer\ -n && composer selfupdate
- composer validate
- composer --prefer-source install
- composer --prefer-source require satooshi/php-coveralls

script:
- bin/test --coverage-clover=build/logs/clover.xml

after_success:
- vendor/bin/coveralls -v
3 changes: 0 additions & 3 deletions CHANGELOG.md

This file was deleted.

3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright (c) 2014 Igor Wiedler
Copyright (c) Bilge 2016.
Portions copyright (C) 2014 Igor Wiedler.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
58 changes: 41 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,50 @@
# retry
Retry
=====

A tiny library for retrying failing operations.
[![Latest version][Version image]][Releases]
[![Build status][Build image]][Build]
[![Test coverage][Coverage image]][Coverage]
[![Code style][Style image]][Style]

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

```php
<?
use function igorw\retry;
Requirements
------------

// retry an operation up to 5 times
$user = retry(5, function () use ($id) {
return User::find($id);
});
- [PHP 5.5](http://php.net/)
- [Composer](https://getcomposer.org/)

Usage
-----

The `retry` function has the following signature.

```
retry(int $times, callable $operation);
```
* `$times` specifies how many times the operation may be called.
* `$operation` is a callback to be run up to the specified number of times.

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.

### Example

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

// this is probably a bad idea
$user = retry(INF, () ==> {
throw new RuntimeException('never gonna give you up');
// Try an operation up to 5 times.
$response = retry(5, function () use ($url) {
return HttpConnector::fetch($url);
});
?>
```

I know. You're welcome.

[Releases]: https://github.com/ScriptFUSION/Retry/releases
[Version image]: https://poser.pugx.org/scriptfusion/retry/v/stable "Latest version"
[Build]: http://travis-ci.org/ScriptFUSION/Retry
[Build image]: https://travis-ci.org/ScriptFUSION/Retry.svg "Build status"
[Coverage]: https://coveralls.io/github/ScriptFUSION/Retry
[Coverage image]: https://coveralls.io/repos/ScriptFUSION/Retry/badge.svg "Test coverage"
[Style]: https://styleci.io/repos/62990558
[Style image]: https://styleci.io/repos/62990558/shield?style=flat "Code style"

5 changes: 5 additions & 0 deletions bin/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

cd "$(dirname "$0")"/..

vendor/bin/phpunit -c test "$@"
45 changes: 25 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
{
"name": "igorw/retry",
"description": "A tiny library for retrying failing operations.",
"keywords": ["failure"],
"license": "MIT",
"authors": [
{
"name": "Igor Wiedler",
"email": "igor@wiedler.ch"
}
],
"require": {
"php": ">=5.4"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
},
"autoload": {
"files": ["src/retry.php"]
"name": "scriptfusion/retry",
"description": "Retries failing operations.",
"license": "MIT",
"authors": [
{
"name": "Bilge",
"email": "bilge@scriptfusion.com"
},
"extra": {
"branch-alias": { "dev-master": "1.0-dev" }
{
"name": "Igor Wiedler",
"email": "igor@wiedler.ch"
}
],
"require": {
"php": "^5.5|^7"
},
"require-dev": {
"phpunit/phpunit": "^4"
},
"autoload": {
"files": [
"src/retry.php"
],
"psr-4": {
"ScriptFUSION\\Retry\\": "src"
}
}
}

0 comments on commit 7504b97

Please sign in to comment.