Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Policies.cs
1using System;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
8{
9 public static class Policies
10 {
11 public static IAsyncPolicy Timeout(TimeSpan timeout) => new TimeoutPolicy(timeout);
12 public static IAsyncPolicy Retry(
13 int maxAttempts,
14 Func<int, Exception, TimeSpan> delayProvider,
15 Action<int, Exception, TimeSpan>? onRetry = null) => new RetryPolicy(maxAttempts, delayProvider, onRetry);
16
17 public static IAsyncPolicy Retry(
18 int maxAttempts,
19 Func<int, Exception, TimeSpan> delayProvider,
20 Func<Exception, bool> shouldRetry,
21 Action<int, Exception, TimeSpan>? onRetry = null) => new RetryPolicy(maxAttempts, delayProvider, onRetry, shouldRetry);
22
23 // Convenience creators for additional policies
24 public static IAsyncPolicy Debounce(TimeSpan delay) => new DebouncePolicy(delay);
25 public static IAsyncPolicy Bulkhead(int maxParallel, int maxQueue = 0, Action? onRejected = null) => new BulkheadPolicy(maxParallel, maxQueue, onRejected);
26 public static IAsyncPolicy CircuitBreaker(int failureThreshold, TimeSpan breakDuration, Action<string>? onStateChange = null)
27 => new CircuitBreakerPolicy(failureThreshold, breakDuration, onStateChange);
28 }
29}
Limits parallel executions, optionally bounding the queue. Rejects when saturated.
Simple circuit breaker: trips after N consecutive failures and stays open for a cool-down....
Delays execution by a quiet period. If a new task run starts during this delay, the run is canceled v...