/
TimeoutStrategyOptions.cs
48 lines (43 loc) · 1.94 KB
/
TimeoutStrategyOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
namespace Polly.Timeout;
/// <summary>
/// Represents the options for the timeout strategy.
/// </summary>
public class TimeoutStrategyOptions : ResilienceStrategyOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="TimeoutStrategyOptions"/> class.
/// </summary>
public TimeoutStrategyOptions() => Name = TimeoutConstants.DefaultName;
/// <summary>
/// Gets or sets the default timeout.
/// </summary>
/// <value>
/// This value must be greater than 10 milliseconds and less than 24 hours. The default value is 30 seconds.
/// </value>
[Range(typeof(TimeSpan), "00:00:00.010", "1.00:00:00")]
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Addressed with DynamicDependency on ValidationHelper.Validate method")]
public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(30);
/// <summary>
/// Gets or sets a timeout generator that generates the timeout for a given execution.
/// </summary>
/// <remarks>
/// If generator returns a <see cref="TimeSpan"/> value that is less or equal to <see cref="TimeSpan.Zero"/>
/// its value is ignored and <see cref="Timeout"/> is used instead. When generator is <see langword="null"/> the <see cref="Timeout"/> is used.
/// <para>
/// Return <see cref="System.Threading.Timeout.InfiniteTimeSpan"/> to disable the timeout for the given execution.
/// </para>
/// </remarks>
/// <value>
/// The default value is <see langword="null"/>.
/// </value>
public Func<TimeoutGeneratorArguments, ValueTask<TimeSpan>>? TimeoutGenerator { get; set; }
/// <summary>
/// Gets or sets the timeout delegate that raised when timeout occurs.
/// </summary>
/// <value>
/// The default value is <see langword="null"/>.
/// </value>
public Func<OnTimeoutArguments, ValueTask>? OnTimeout { get; set; }
}