Class CircuitBreakerOptions<TResult>

Namespace
Kevlar
Assembly
Kevlar.dll

Result-typed configuration for a circuit breaker strategy on a Shield<TResult>.

public sealed class CircuitBreakerOptions<TResult>

Type Parameters

TResult
Inheritance
CircuitBreakerOptions<TResult>
Inherited Members

Remarks

CircuitBreakerOptions<TResult> and CircuitBreakerOptions are standalone sibling types with matching shared property names and defaults.

Constructors

CircuitBreakerOptions()

public CircuitBreakerOptions()

Properties

BreakDuration

How long the circuit stays open before allowing a probe. Default 15 seconds.

public TimeSpan BreakDuration { get; set; }

Property Value

TimeSpan

BreakDurationGenerator

Produces the break duration when a handled outcome trips or re-opens the circuit, and is awaited before the circuit opens. The returned value must be positive. Return new(duration) from a synchronous generator. The event context is valid only until the returned task completes. When configured, this value overrides BreakDuration.

public Func<CircuitBreakerBreakDurationEvent<TResult>, ValueTask<TimeSpan>>? BreakDurationGenerator { get; set; }

Property Value

Func<CircuitBreakerBreakDurationEvent<TResult>, ValueTask<TimeSpan>>

ConsecutiveFailures

Trips the circuit after this many consecutive handled failures.

public int? ConsecutiveFailures { get; set; }

Property Value

int?

FailureRatio

Trips the circuit when the ratio of handled failures within SamplingWindow reaches this value (0 to 1), provided at least MinimumThroughput executions were observed in the window.

public double? FailureRatio { get; set; }

Property Value

double?

HandlesException

Setting this — or, on CircuitBreakerOptions<TResult>, its HandlesResult — makes this circuit breaker ignore the ambient When… handling clause; this predicate then selects the exceptions it handles.

public Func<Exception, bool>? HandlesException { get; set; }

Property Value

Func<Exception, bool>

Remarks

The ambient clause is started with When… on a shield and continued with Or… on the builder it returns, and applies to every reactive strategy chained after it. These properties replace that clause for this strategy alone; they do not narrow it.

See Also

HandlesExceptionContext

Locally handles exceptions using the typed outcome and execution context.

public Func<HandlingEvent<TResult>, bool>? HandlesExceptionContext { get; set; }

Property Value

Func<HandlingEvent<TResult>, bool>

HandlesResult

Setting this — or HandlesException — makes this circuit breaker ignore the ambient When… handling clause; this predicate then selects the results it handles.

public Func<TResult, bool>? HandlesResult { get; set; }

Property Value

Func<TResult, bool>

Remarks

The ambient clause is started with When…/WhenResult… on a shield and continued with Or… on the builder it returns, and applies to every reactive strategy chained after it. These properties replace that clause for this strategy alone; they do not narrow it.

See Also

HandlesResultContext

Locally handles results using the typed outcome and execution context.

public Func<HandlingEvent<TResult>, bool>? HandlesResultContext { get; set; }

Property Value

Func<HandlingEvent<TResult>, bool>

MinimumThroughput

Minimum executions in the sampling window before FailureRatio can trip the circuit. Default 10.

public int MinimumThroughput { get; set; }

Property Value

int

Monitor

An optional monitor giving external code visibility of the circuit state plus manual Isolate() / Reset() control. A monitor can be bound to only one circuit breaker.

public CircuitBreakerMonitor? Monitor { get; set; }

Property Value

CircuitBreakerMonitor

Name

An optional low-cardinality name used by strategy telemetry.

public string? Name { get; set; }

Property Value

string

OnStateChanged

Invoked and awaited on every state transition, before StateChanged. Transitions are delivered serially outside the circuit lock, so a slow handler delays later transition publishers. Return default from a synchronous callback. The event context is valid only until the returned task completes. A non-reentrant publisher arriving during an active drain waits for the earlier handlers; an execution may therefore occupy a thread-pool thread until they return. A publisher reentered from OnStateChanged or StateChanged is queued and returns before the queued transition's observers run.

public Func<CircuitBreakerStateChangedEvent, ValueTask>? OnStateChanged { get; set; }

Property Value

Func<CircuitBreakerStateChangedEvent, ValueTask>

SamplingWindow

The rolling window over which the failure ratio is measured. Default 30 seconds.

public TimeSpan SamplingWindow { get; set; }

Property Value

TimeSpan