Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DebouncePolicy.cs
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4
6{
12 {
13 private readonly TimeSpan delay;
14
15 public DebouncePolicy(TimeSpan Delay)
16 {
17 ArgumentOutOfRangeException.ThrowIfLessThan(Delay, TimeSpan.Zero);
18 this.delay = Delay;
19 }
20
21 public async Task ExecuteAsync(Func<CancellationToken, Task> action, CancellationToken ct)
22 {
23 if (this.delay > TimeSpan.Zero)
24 await Task.Delay(this.delay, ct);
25
26 await action(ct);
27 }
28
29 public async Task<T> ExecuteAsync<T>(Func<CancellationToken, Task<T>> action, CancellationToken ct)
30 {
31 if (this.delay > TimeSpan.Zero)
32 await Task.Delay(this.delay, ct);
33
34 return await action(ct);
35 }
36 }
37}
38
Delays execution by a quiet period. If a new task run starts during this delay, the run is canceled v...
async Task< T > ExecuteAsync< T >(Func< CancellationToken, Task< T > > action, CancellationToken ct)
Executes an async action producing a value through the policy pipeline.