Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SyncTask0.cs
1using System;
2using System.Threading.Tasks;
3
5{
10 public class SyncTask0<ReturnType> : ISyncTask
11 {
15 protected readonly TaskCompletionSource<ReturnType> task;
16
17 private readonly Callback0<ReturnType> callback;
18
24 {
25 this.task = new TaskCompletionSource<ReturnType>();
26 this.callback = Callback;
27 }
28
32 public void Execute()
33 {
34 try
35 {
36 this.task.TrySetResult(this.callback());
37 }
38 catch (Exception ex)
39 {
40 this.task.TrySetException(ex);
41 }
42 }
43
48 public Task<ReturnType> WaitAsync() => this.task.Task;
49 }
50}
Task with zero arguments to be synchronized.
Definition: SyncTask0.cs:11
Task< ReturnType > WaitAsync()
Waits for the task to complete.
void Execute()
Executes the task.
Definition: SyncTask0.cs:32
SyncTask0(Callback0< ReturnType > Callback)
Task to be synchronized.
Definition: SyncTask0.cs:23
readonly TaskCompletionSource< ReturnType > task
Task completion source, waiting for the result of the task.
Definition: SyncTask0.cs:15
Interface for tasks to be synckronized.
Definition: ISyncTask.cs:7
delegate ReturnType Callback0< ReturnType >()
Delegate to methods of zero parameters and a given return type.