### ----------------------------------------------------
### -- Retry
### -- Licenses: Artistic-2.0
### -- Authors: Haytham Elganiny
### -- File: t/01-basic.rakutest
### ----------------------------------------------------
use Test;
use Retry;


plan 6;

sub eventually-lives {

  sub {
    die unless $++ > 0;

    True
  }

}

sub always-dies {

    sub {
        die;
    }

}


lives-ok {

  retry eventually-lives

}, 'retry success in second attempt';


dies-ok { retry( always-dies, :1max ) }, 'dies when always fail';


lives-ok {
    retry eventually-lives, :delay({ (1/10..3/10).pick });
}, 'retry delayed by Code';


dies-ok {
    retry always-dies, :delay({ 0 });
}, 'retry delayed by Code';

lives-ok {
    retry eventually-lives, :max(Inf);
}, ‚we can retry for ∞‘;

lives-ok {
    retry eventually-lives, :max(*);
}, ‚we can retry for *‘;

done-testing;


