Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SyncTask2.cs
1using System;
2using System.Threading.Tasks;
3
5{
12 public class SyncTask2<ReturnType, Arg1Type, Arg2Type> : ISyncTask
13 {
17 protected readonly TaskCompletionSource<ReturnType> task;
18
19 private readonly Callback2<ReturnType, Arg1Type, Arg2Type> callback;
20 private readonly Arg1Type arg1;
21 private readonly Arg2Type arg2;
22
29 public SyncTask2(Callback2<ReturnType, Arg1Type, Arg2Type> Callback, Arg1Type Arg1, Arg2Type Arg2)
30 {
31 this.task = new TaskCompletionSource<ReturnType>();
32 this.callback = Callback;
33 this.arg1 = Arg1;
34 this.arg2 = Arg2;
35 }
36
40 public void Execute()
41 {
42 try
43 {
44 this.task.TrySetResult(this.callback(this.arg1, this.arg2));
45 }
46 catch (Exception ex)
47 {
48 this.task.TrySetException(ex);
49 }
50 }
51
56 public Task<ReturnType> WaitAsync() => this.task.Task;
57 }
58}
Task with one argument to be synchronized.
Definition: SyncTask2.cs:13
SyncTask2(Callback2< ReturnType, Arg1Type, Arg2Type > Callback, Arg1Type Arg1, Arg2Type Arg2)
Task to be synchronized.
Definition: SyncTask2.cs:29
void Execute()
Executes the task.
Definition: SyncTask2.cs:40
Task< ReturnType > WaitAsync()
Waits for the task to complete.
readonly TaskCompletionSource< ReturnType > task
Task completion source, waiting for the result of the task.
Definition: SyncTask2.cs:17
Interface for tasks to be synckronized.
Definition: ISyncTask.cs:7
delegate ReturnType Callback2< ReturnType, Arg1Type, Arg2Type >(Arg1Type Arg1, Arg2Type Arg2)
Delegate to methods of two parameters and a given return type.