Mercurial > pub > ImplabNet
comparison Implab.Test/RunnableComponentTests.cs @ 259:7d52dc684bbd v3
PollingComponent: implemented correct stopping
author | cin |
---|---|
date | Fri, 13 Apr 2018 03:57:39 +0300 |
parents | |
children | 547a2fc0d93e |
comparison
equal
deleted
inserted
replaced
258:d0876436d95d | 259:7d52dc684bbd |
---|---|
1 using System; | |
2 using System.Threading; | |
3 using System.Threading.Tasks; | |
4 using Implab.Components; | |
5 using Xunit; | |
6 | |
7 namespace Implab.Test | |
8 { | |
9 class TimeLog : PollingComponent { | |
10 public TimeLog() : base(true) { | |
11 } | |
12 | |
13 protected override Task Poll(CancellationToken ct) { | |
14 Console.WriteLine("Poll"); | |
15 return Task.CompletedTask; | |
16 } | |
17 } | |
18 | |
19 public class UnitTest1 | |
20 { | |
21 [Fact] | |
22 public async Task Test1() | |
23 { | |
24 | |
25 using(var tl = new TimeLog()) { | |
26 tl.StateChanged += (self, args) => Console.WriteLine("{0}", args.State); | |
27 tl.Delay = 1000; | |
28 tl.Interval = 500; | |
29 | |
30 | |
31 tl.Start(CancellationToken.None); | |
32 await tl.Completion; | |
33 | |
34 await Task.Delay(2000); | |
35 | |
36 tl.Stop(CancellationToken.None); | |
37 await tl.Completion; | |
38 await Task.Delay(3000); | |
39 } | |
40 } | |
41 } | |
42 } |