annotate Implab.Test/PromiseHelper.cs @ 266:254d1f255d87 v3

Добавлена метка v3.0.10 для набора изменений 74e048cbaac8
author cin
date Mon, 16 Apr 2018 19:45:18 +0300
parents d82909310094
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
249
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
1 using Implab;
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
2 using System;
10
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents:
diff changeset
3 using System.Threading;
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents:
diff changeset
4
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents:
diff changeset
5 namespace Implab.Test {
77
91362ffbecf8 ported tests to mono
cin
parents: 73
diff changeset
6 static class PromiseHelper {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
7 public static IPromise<T> Sleep<T>(int timeout, T retVal, CancellationToken ct = default(CancellationToken)) {
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
8
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
9 Timer timer = null;
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
10
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
11 return Promise.Create<T>((d) => {
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
12 timer = new Timer(x => {
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
13 d.Resolve(retVal);
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
14 }, null, timeout, Timeout.Infinite);
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
15
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
16 if(ct.CanBeCanceled)
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
17 ct.Register(d.Cancel);
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
18
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
19 }).Finally(() => {
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
20 Safe.Dispose(timer);
10
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents:
diff changeset
21 });
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents:
diff changeset
22 }
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 149
diff changeset
23
249
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
24 public static IPromise Sleep(int timeout, CancellationToken ct = default(CancellationToken)) {
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
25 Timer timer = null;
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
26
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
27 return Promise.Create((d) => {
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
28 timer = new Timer(x => {
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
29 d.Resolve();
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
30 }, null, timeout, Timeout.Infinite);
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
31
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
32 if(ct.CanBeCanceled)
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
33 ct.Register(d.Cancel);
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
34
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
35 }).Finally(() => {
d82909310094 Implab.Test moved to xunit
cin
parents: 203
diff changeset
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
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents:
diff changeset
39 }
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents:
diff changeset
40 }