public Circuit(int threshold, TimeSpan?timeout = null, CircuitState state = null) { Threshold = threshold; if (timeout.HasValue) { Timeout = timeout.Value; } State = state ?? new CircuitState { Position = CircuitPosition.Closed }; ExceptionFilters = new List <Func <Exception, bool> >(); }
protected void HandleException(Exception exception, CircuitState state) { if (ExceptionFilters.Any(filter => filter(exception))) { return; } if (ExcludedExceptions == null || !ExcludedExceptions.Contains(exception.GetType())) { state.ResetTime = DateTime.UtcNow.Add(Timeout); state.Increment(); if (state.Position == CircuitPosition.HalfOpen || state.CurrentIteration >= Threshold) { state.Position = CircuitPosition.Open; } Logger?.Invoke(exception.Message); } }