Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
WorkItem.cs
1using System.Threading;
2using System.Threading.Tasks;
3
5{
9 public abstract class WorkItem : IWorkItem
10 {
11 private readonly TaskCompletionSource<bool> processed = new TaskCompletionSource<bool>();
12
16 public Task Execute()
17 {
18 return this.Execute(CancellationToken.None);
19 }
20
25 public abstract Task Execute(CancellationToken Cancel);
26
31 public void Processed(bool Result)
32 {
33 this.processed.TrySetResult(Result);
34 }
35
40 public Task<bool> Wait()
41 {
42 return this.processed.Task;
43 }
44
50 public Task<bool> Wait(CancellationToken Cancel)
51 {
52 if (Cancel.CanBeCanceled)
53 Cancel.Register(() => this.processed.TrySetResult(false));
54
55 return this.processed.Task;
56 }
57 }
58}
Represents an asynchronous operation to be performed.
Definition: WorkItem.cs:10
abstract Task Execute(CancellationToken Cancel)
Executes the operation.
Task< bool > Wait(CancellationToken Cancel)
Waits for the item to be processed.
Definition: WorkItem.cs:50
Task Execute()
Executes the operation.
Definition: WorkItem.cs:16
Task< bool > Wait()
Waits for the item to be processed.
Definition: WorkItem.cs:40
void Processed(bool Result)
Flags the item as processed.
Definition: WorkItem.cs:31
Interface for asynchronous operations.
Definition: IWorkItem.cs:10