Mercurial > pub > ImplabNet
annotate Implab.Test/PromiseHelper.cs @ 281:e0916ddc9950 v3 tip
code cleanup and refactoring
author | cin |
---|---|
date | Fri, 01 Jun 2018 21:35:24 +0300 |
parents | d82909310094 |
children |
rev | line source |
---|---|
249 | 1 using Implab; |
2 using System; | |
10 | 3 using System.Threading; |
4 | |
5 namespace Implab.Test { | |
77 | 6 static class PromiseHelper { |
249 | 7 public static IPromise<T> Sleep<T>(int timeout, T retVal, CancellationToken ct = default(CancellationToken)) { |
8 | |
9 Timer timer = null; | |
10 | |
11 return Promise.Create<T>((d) => { | |
12 timer = new Timer(x => { | |
13 d.Resolve(retVal); | |
14 }, null, timeout, Timeout.Infinite); | |
15 | |
16 if(ct.CanBeCanceled) | |
17 ct.Register(d.Cancel); | |
18 | |
19 }).Finally(() => { | |
20 Safe.Dispose(timer); | |
10 | 21 }); |
22 } | |
203
4d9830a9bbb8
Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
149
diff
changeset
|
23 |
249 | 24 public static IPromise Sleep(int timeout, CancellationToken ct = default(CancellationToken)) { |
25 Timer timer = null; | |
26 | |
27 return Promise.Create((d) => { | |
28 timer = new Timer(x => { | |
29 d.Resolve(); | |
30 }, null, timeout, Timeout.Infinite); | |
31 | |
32 if(ct.CanBeCanceled) | |
33 ct.Register(d.Cancel); | |
34 | |
35 }).Finally(() => { | |
36 Safe.Dispose(timer); | |
203
4d9830a9bbb8
Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
149
diff
changeset
|
37 }); |
4d9830a9bbb8
Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
149
diff
changeset
|
38 } |
10 | 39 } |
40 } |