Mercurial > pub > ImplabNet
diff Implab/PromiseExtensions.cs @ 190:1c2a16d071a7 v2
Слияние с ref20160224
author | cin |
---|---|
date | Fri, 22 Apr 2016 13:08:08 +0300 |
parents | 822aab37b107 |
children | 8200ab154c8a |
line wrap: on
line diff
--- a/Implab/PromiseExtensions.cs Fri Feb 19 18:07:17 2016 +0300 +++ b/Implab/PromiseExtensions.cs Fri Apr 22 13:08:08 2016 +0300 @@ -3,11 +3,6 @@ using Implab.Diagnostics; using System.Collections.Generic; - -#if NET_4_5 -using System.Threading.Tasks; -#endif - namespace Implab { public static class PromiseExtensions { public static IPromise<T> DispatchToCurrentContext<T>(this IPromise<T> that) { @@ -17,12 +12,12 @@ return that; var p = new SyncContextPromise<T>(context); - p.On(that.Cancel, PromiseEventType.Cancelled); + p.CancellationRequested(that.Cancel); that.On( p.Resolve, p.Reject, - p.Cancel + p.CancelOperation ); return p; } @@ -32,13 +27,12 @@ Safe.ArgumentNotNull(context, "context"); var p = new SyncContextPromise<T>(context); - p.On(that.Cancel, PromiseEventType.Cancelled); - + p.CancellationRequested(that.Cancel); that.On( p.Resolve, p.Reject, - p.Cancel + p.CancelOperation ); return p; } @@ -77,8 +71,8 @@ }; } - static void CancelCallback(object cookie) { - ((ICancellable)cookie).Cancel(); + static void CancelByTimeoutCallback(object cookie) { + ((ICancellable)cookie).Cancel(new TimeoutException()); } /// <summary> @@ -89,7 +83,7 @@ /// <typeparam name="TPromise">The 1st type parameter.</typeparam> public static TPromise Timeout<TPromise>(this TPromise that, int milliseconds) where TPromise : IPromise { Safe.ArgumentNotNull(that, "that"); - var timer = new Timer(CancelCallback, that, milliseconds, -1); + var timer = new Timer(CancelByTimeoutCallback, that, milliseconds, -1); that.On(timer.Dispose, PromiseEventType.All); return that; } @@ -180,8 +174,7 @@ var d = new ActionTask(success, error, cancel, false); that.On(d.Resolve, d.Reject, d.CancelOperation); - if (success != null) - d.CancellationRequested(that.Cancel); + d.CancellationRequested(that.Cancel); return d; } @@ -198,8 +191,7 @@ var d = new FuncTask<T>(success, error, cancel, false); that.On(d.Resolve, d.Reject, d.CancelOperation); - if (success != null) - d.CancellationRequested(that.Cancel); + d.CancellationRequested(that.Cancel); return d; } @@ -215,8 +207,7 @@ Safe.ArgumentNotNull(that, "that"); var d = new FuncTask<T,T2>(success, error, cancel, false); that.On(d.Resolve, d.Reject, d.CancelOperation); - if (success != null) - d.CancellationRequested(that.Cancel); + d.CancellationRequested(that.Cancel); return d; } @@ -234,8 +225,7 @@ var d = new ActionChainTask(success, error, cancel, false); that.On(d.Resolve, d.Reject, d.CancelOperation); - if (success != null) - d.CancellationRequested(that.Cancel); + d.CancellationRequested(that.Cancel); return d; }