Predicate filter
A predicate can provide advanced criteria and filtering logic.
public void AttemptCall(Action action, Predicate<Exception> match) { try { action(); } catch(Exception e) { if(match(e)) state.ActUponException(e); throw; } }
For example, you can only increase the circuit breaker on a WebException caused by a timeout.
circuitBreaker.AttemptCall(() => service.DoWork(), e => { WebException local = e as WebException; if(local == null) return false; return local.Status == WebExceptionStatus.Timeout; });
source share