There are several policy's that need to be the same throughout my code. For example:
var myIOProblems = Policy
.Handle<IOException>()
.WaitAndRetryForever(i => TimeSpan.FromSeconds(2));
Then I'll have some code that will do the work:
myIOProblems
.Execute(() => otherPath.CopyTo(otherPathPart.FullName));
This works great, and I can litter the latter statements all over my code, change the behavior in one central place, and it all seems to work.
But in some places I need to provide the user/framework some feedback that problems are occurring. I can write a new policy:
Policy
.Handle<IOException>()
.WaitAndRetryForever(i => TimeSpan.FromSeconds(2), (e, t, c) =>
{
count++;
statusUpdate.PCall($"Copying {otherPath.Name}: {other.Name} -> {Name} (retry ({count}): {e.Message})");
})
.Execute(() => otherPath.CopyTo(otherPathPart.FullName));
But now I've lost the ability to re-use common code. What I'd really like to be able to write is something like the following:
myIOProblems
.OnRetry(e => statusUpdate.PCall($"Error ({e.Message}), retrying"))
.Execute(() => otherPath.CopyTo(otherPathPart.FullName));
Or something similar to that. I may be overlooking something in the library, in which case I apologize!