##// END OF EJS Templates
Added tests for Implab.ServiceHost.Unity configuration loader.
Added tests for Implab.ServiceHost.Unity configuration loader.

File last commit:

r289:95896f882995 v3.0.14 v3
r289:95896f882995 v3.0.14 v3
Show More
PromiseHelper.cs
40 lines | 1.1 KiB | text/x-csharp | CSharpLexer
using Implab;
using System;
using System.Threading;
namespace Implab.Test {
static class PromiseHelper {
public static IPromise<T> Sleep<T>(int timeout, T retVal, CancellationToken ct = default(CancellationToken)) {
Timer timer = null;
return Promise.Create<T>((d) => {
timer = new Timer(x => {
d.Resolve(retVal);
}, null, timeout, Timeout.Infinite);
if(ct.CanBeCanceled)
ct.Register(d.Cancel);
}).Finally(() => {
Safe.Dispose(timer);
});
}
public static IPromise Sleep(int timeout, CancellationToken ct = default(CancellationToken)) {
Timer timer = null;
return Promise.Create((d) => {
timer = new Timer(x => {
d.Resolve();
}, null, timeout, Timeout.Infinite);
if(ct.CanBeCanceled)
ct.Register(d.Cancel);
}).Finally(() => {
Safe.Dispose(timer);
});
}
}
}