annotate Implab.Test/MockPollComponent.cs @ 281:e0916ddc9950 v3 tip

code cleanup and refactoring
author cin
date Fri, 01 Jun 2018 21:35:24 +0300
parents f1696cdc3d7a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
260
547a2fc0d93e minor fixes
cin
parents:
diff changeset
1 using System;
547a2fc0d93e minor fixes
cin
parents:
diff changeset
2 using System.Threading;
547a2fc0d93e minor fixes
cin
parents:
diff changeset
3 using System.Threading.Tasks;
547a2fc0d93e minor fixes
cin
parents:
diff changeset
4 using Implab.Components;
547a2fc0d93e minor fixes
cin
parents:
diff changeset
5
547a2fc0d93e minor fixes
cin
parents:
diff changeset
6 namespace Implab.Test {
547a2fc0d93e minor fixes
cin
parents:
diff changeset
7 public class MockPollComponent : PollingComponent {
547a2fc0d93e minor fixes
cin
parents:
diff changeset
8
547a2fc0d93e minor fixes
cin
parents:
diff changeset
9 public Func<CancellationToken,Task> PollWorker { get; set;}
547a2fc0d93e minor fixes
cin
parents:
diff changeset
10
547a2fc0d93e minor fixes
cin
parents:
diff changeset
11 public Func<CancellationToken, Task> StartWorker { get; set; }
547a2fc0d93e minor fixes
cin
parents:
diff changeset
12
547a2fc0d93e minor fixes
cin
parents:
diff changeset
13 public Func<CancellationToken, Task> StopWorker { get; set; }
547a2fc0d93e minor fixes
cin
parents:
diff changeset
14
547a2fc0d93e minor fixes
cin
parents:
diff changeset
15 public MockPollComponent(bool initialized) : base(initialized) {
547a2fc0d93e minor fixes
cin
parents:
diff changeset
16 }
547a2fc0d93e minor fixes
cin
parents:
diff changeset
17
547a2fc0d93e minor fixes
cin
parents:
diff changeset
18 protected async override Task Poll(CancellationToken ct) {
547a2fc0d93e minor fixes
cin
parents:
diff changeset
19 if(PollWorker!= null)
547a2fc0d93e minor fixes
cin
parents:
diff changeset
20 await PollWorker.Invoke(ct);
547a2fc0d93e minor fixes
cin
parents:
diff changeset
21 }
547a2fc0d93e minor fixes
cin
parents:
diff changeset
22
547a2fc0d93e minor fixes
cin
parents:
diff changeset
23 protected async override Task StopInternalAsync(CancellationToken ct) {
262
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 260
diff changeset
24 await base.StopInternalAsync(ct);
260
547a2fc0d93e minor fixes
cin
parents:
diff changeset
25 if (StopWorker != null)
547a2fc0d93e minor fixes
cin
parents:
diff changeset
26 await StopWorker.Invoke(ct);
547a2fc0d93e minor fixes
cin
parents:
diff changeset
27 }
547a2fc0d93e minor fixes
cin
parents:
diff changeset
28
547a2fc0d93e minor fixes
cin
parents:
diff changeset
29 protected async override Task StartInternalAsync(CancellationToken ct) {
262
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 260
diff changeset
30 await base.StartInternalAsync(ct);
260
547a2fc0d93e minor fixes
cin
parents:
diff changeset
31 if (StartWorker != null)
547a2fc0d93e minor fixes
cin
parents:
diff changeset
32 await StartWorker.Invoke(ct);
547a2fc0d93e minor fixes
cin
parents:
diff changeset
33 }
547a2fc0d93e minor fixes
cin
parents:
diff changeset
34
547a2fc0d93e minor fixes
cin
parents:
diff changeset
35
547a2fc0d93e minor fixes
cin
parents:
diff changeset
36 }
547a2fc0d93e minor fixes
cin
parents:
diff changeset
37 }