Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
MaxCountProcessor.cs
1using System.Threading.Tasks;
3
5{
9 public class MaxCountProcessor : IProcessor<object>
10 {
11 private readonly IProcessor<object> processor;
12 private readonly bool isAsynchronous;
13 private int count;
14
20 public MaxCountProcessor(IProcessor<object> Processor, int Count)
21 {
22 this.processor = Processor;
23 this.count = Count;
24 this.isAsynchronous = Processor.IsAsynchronous;
25 }
26
30 public bool IsAsynchronous => this.isAsynchronous;
31
37 public bool Process(object Object)
38 {
39 if (this.count <= 0)
40 return false;
41
42 this.count--;
43 return this.processor.Process(Object);
44 }
45
51 public Task<bool> ProcessAsync(object Object)
52 {
53 if (this.count <= 0)
54 return Task.FromResult(false);
55
56 this.count--;
57 return this.processor.ProcessAsync(Object);
58 }
59
64 public bool Flush() => this.processor.Flush();
65
70 public Task<bool> FlushAsync() => this.processor.FlushAsync();
71 }
72}
Processor that limits the return set to a maximum number of records.
MaxCountProcessor(IProcessor< object > Processor, int Count)
Enumerator that limits the return set to a maximum number of records.
Task< bool > ProcessAsync(object Object)
Processes an object asynchronously.
Task< bool > FlushAsync()
Called at the end of processing, to allow for flushing of buffers, etc.
bool IsAsynchronous
If the processor operates asynchronously.
bool Process(object Object)
Processes an object synchronously.
bool Flush()
Called at the end of processing, to allow for flushing of buffers, etc.
Interface for processors of objects.
Definition: IProcessor.cs:9
bool IsAsynchronous
If the processor operates asynchronously.
Definition: IProcessor.cs:13