2017 © Pedro Peláez
 

library evacuator

Try-catch with multiple retries

image

serafim/evacuator

Try-catch with multiple retries

  • Thursday, December 29, 2016
  • by Serafim
  • Repository
  • 2 Watchers
  • 17 Stars
  • 138 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Evacuator 3.0

Build Status Code Quality, (*1)

He trying to save your code, if it is broken :3, (*2)

Installation

composer require serafim/evacuator, (*3)

Link to Packagist, (*4)

Usage example

// What we are trying to keep safe?
$result = rescue(function () { 
    if (random_int(0, 9999) > 1) {
        throw new \Exception('Ooooups =(');
    }

    return 23;
});

var_dump($result); // int(23)

Advanced usage

use Serafim\Evacuator\Evacuator;

$result = (new Evacuator(function() {

    // Your a very important piece of code

}))

    // Code throws an exception after 100500 call retries 
    ->retry(100500) 

    // or until the cancer is not on the mountain whistles...
    ->retry(Evacuator::INFINITY_RETRIES) 

    // But if you want catch exception
    ->catch(function (Throwable $e) {
        return 'Something went wrong =('; // Will be returns into $result
    })

    ->finally(function ($errorOrResult) {
        // Run this code after all attempts.
        // $errorOrResult can be error (if evacuator cant keep safe your code) or result value
    })

    ->onError(function ($error) {
        // Run this code after every error
    })

    ->invoke(); // Just run your very important code

Catching strategy

$result = (new Evacuator(function() {
    throw new \LogicException('Error');
}))

    ->catch(function (\RuntimeException $e) {
        // I am alone and never be use ='( 
    })
    // ->onError(function (\RuntimeException $e) {})

    ->catch(function (\LogicException $e) {
        // Yay! I will calling because Im a LogicException! :D
    })
    // ->onError(function (\LogicException $e) {})

    ->invoke();

Enjoy! :3, (*5)

The Versions

29/12 2016

dev-master

9999999-dev https://github.com/SerafimArts/Evacuator

Try-catch with multiple retries

  Sources   Download

WTFPL

The Requires

  • php >=7.0

 

The Development Requires

29/12 2016

3.0.0

3.0.0.0 https://github.com/SerafimArts/Evacuator

Try-catch with multiple retries

  Sources   Download

WTFPL

The Requires

  • php >=7.0

 

The Development Requires

05/05 2016

2.0.0

2.0.0.0 https://github.com/SerafimArts/Evacuator

Try-catch with multiple retries

  Sources   Download

WTFPL

The Requires

  • php >=5.6

 

06/04 2016

1.0.0

1.0.0.0 https://github.com/SerafimArts/Evacuator

Try-catch with multiple retries

  Sources   Download

WTFPL

The Requires

  • php >=7.0