Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SyncTask1.cs
1using System;
2using System.Threading.Tasks;
3
5{
11 public class SyncTask1<ReturnType, Arg1Type> : ISyncTask
12 {
16 protected readonly TaskCompletionSource<ReturnType> task;
17
18 private readonly Callback1<ReturnType, Arg1Type> callback;
19 private readonly Arg1Type arg1;
20
26 public SyncTask1(Callback1<ReturnType, Arg1Type> Callback, Arg1Type Arg1)
27 {
28 this.task = new TaskCompletionSource<ReturnType>();
29 this.callback = Callback;
30 this.arg1 = Arg1;
31 }
32
36 public void Execute()
37 {
38 try
39 {
40 this.task.TrySetResult(this.callback(this.arg1));
41 }
42 catch (Exception ex)
43 {
44 this.task.TrySetException(ex);
45 }
46 }
47
52 public Task<ReturnType> WaitAsync() => this.task.Task;
53 }
54}
Task with one argument to be synchronized.
Definition: SyncTask1.cs:12
SyncTask1(Callback1< ReturnType, Arg1Type > Callback, Arg1Type Arg1)
Task to be synchronized.
Definition: SyncTask1.cs:26
void Execute()
Executes the task.
Definition: SyncTask1.cs:36
readonly TaskCompletionSource< ReturnType > task
Task completion source, waiting for the result of the task.
Definition: SyncTask1.cs:16
Task< ReturnType > WaitAsync()
Waits for the task to complete.
Interface for tasks to be synckronized.
Definition: ISyncTask.cs:7
delegate ReturnType Callback1< ReturnType, Arg1Type >(Arg1Type Arg1)
Delegate to methods of one parameter and a given return type.