A smiple retry library. It's just a fancy do while loop without 'retry policies'
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
LICENSE
README.md

README.md

Treadmill

A smiple retry library. It's just a fancy do while loop without 'retry policies'.

var retry = new Tread();

//This tries until the exception is null, or 10 tries
retry.Try(
    action: () => { Console.WriteLine("Hello Retry"); },
    tryCount: 10,
    until: ex => ex == null
);
//In this case, the expectation is that only one iteration will happen.

//This tries until the exception is null and the result of the func is not null or whitespace
var result = retry.Try(
    func: () => DateTime.Now.Millisecond % 2 == 0 ? Guid.NewGuid().ToString("N") : string.Empty,
    until: (strResult, exception) => exception == null && !String.IsNullOrWhiteSpace(strResult),
    tryCount: 5
);
//In this case, we expect a random iteration count based on current milliseconds being even.

//Note: Some care should be taken to avoid swallowing errors with this code. There are hooks to log errors that shouldn't be ignored.
//I'm debating throwing the error, or aggregate error, when until conditions are not met by the last iteration. Thoughts?
            

Blog about this lib