Skip to content

Commit

Permalink
Fixed CB open state should return a faulted Task instead of throwing (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaelhamed authored Jul 25, 2021
1 parent fb9a2d5 commit f2b99b4
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/core/Akka/Pattern/CircuitBreakerState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,21 @@ private TimeSpan RemainingDuration()
}

/// <summary>
/// N/A
/// Fail-fast on any invocation
/// </summary>
/// <typeparam name="T">N/A</typeparam>
/// <param name="body">Implementation of the call that needs protected</param>
/// <exception cref="OpenCircuitException">This exception is thrown automatically since the circuit is open.</exception>
/// <returns>N/A</returns>
public override Task<T> Invoke<T>(Func<Task<T>> body)
{
throw new OpenCircuitException(_breaker.LastCaughtException, RemainingDuration());
}
/// <returns><see cref="Task"/> containing result of protected call</returns>
public override Task<T> Invoke<T>(Func<Task<T>> body) =>
Task.FromException<T>(new OpenCircuitException(_breaker.LastCaughtException, RemainingDuration()));

/// <summary>
/// N/A
/// Fail-fast on any invocation
/// </summary>
/// <param name="body">Implementation of the call that needs protected</param>
/// <exception cref="OpenCircuitException">This exception is thrown automatically since the circuit is open.</exception>
/// <returns>N/A</returns>
public override Task Invoke(Func<Task> body)
{
throw new OpenCircuitException(_breaker.LastCaughtException, RemainingDuration());
}
/// <returns><see cref="Task"/> containing result of protected call</returns>
public override Task Invoke(Func<Task> body) =>
Task.FromException(new OpenCircuitException(_breaker.LastCaughtException, RemainingDuration()));

/// <summary>
/// No-op for open, calls are never executed so cannot succeed or fail
Expand Down Expand Up @@ -132,7 +126,6 @@ public HalfOpen(CircuitBreaker breaker)
/// </summary>
/// <typeparam name="T">TBD</typeparam>
/// <param name="body">Implementation of the call that needs protected</param>
/// <exception cref="OpenCircuitException">TBD</exception>
/// <returns><see cref="Task"/> containing result of protected call</returns>
public override async Task<T> Invoke<T>(Func<Task<T>> body)
{
Expand All @@ -148,7 +141,6 @@ public override async Task<T> Invoke<T>(Func<Task<T>> body)
/// If the call succeeds, the breaker closes.
/// </summary>
/// <param name="body">Implementation of the call that needs protected</param>
/// <exception cref="OpenCircuitException">TBD</exception>
/// <returns><see cref="Task"/> containing result of protected call</returns>
public override async Task Invoke(Func<Task> body)
{
Expand Down

0 comments on commit f2b99b4

Please sign in to comment.