comparison Implab/PromiseExtensions.cs @ 76:c761fc982e1d v2

Refactoring of the IPromise<T> interface Added tests
author cin
date Wed, 10 Sep 2014 17:53:05 +0400
parents 4439140706d0
children 279e226dffdd
comparison
equal deleted inserted replaced
75:4439140706d0 76:c761fc982e1d
12 if (context == null) 12 if (context == null)
13 return that; 13 return that;
14 14
15 var p = new SyncContextPromise<T>(context, that, true); 15 var p = new SyncContextPromise<T>(context, that, true);
16 16
17 that.Then( 17 that.Last(
18 x => p.Resolve(x), 18 p.Resolve,
19 e => { 19 p.Reject,
20 p.Reject(e); 20 p.Cancel
21 return default(T);
22 }
23 ); 21 );
24 return p; 22 return p;
25 } 23 }
26 24
27 public static IPromise<T> DispatchToContext<T>(this IPromise<T> that, SynchronizationContext context) { 25 public static IPromise<T> DispatchToContext<T>(this IPromise<T> that, SynchronizationContext context) {
28 Safe.ArgumentNotNull(that, "that"); 26 Safe.ArgumentNotNull(that, "that");
29 Safe.ArgumentNotNull(context, "context"); 27 Safe.ArgumentNotNull(context, "context");
30 28
31 var p = new SyncContextPromise<T>(context, that, true); 29 var p = new SyncContextPromise<T>(context, that, true);
32 30
33 that.Then( 31 that.Last(
34 x => p.Resolve(x), 32 p.Resolve,
35 e => { 33 p.Reject,
36 p.Reject(e); 34 p.Cancel
37 return default(T);
38 }
39 ); 35 );
40 return p; 36 return p;
41 } 37 }
42 38
43 public static AsyncCallback AsyncCallback<T>(this Promise<T> that, Func<IAsyncResult,T> callback) { 39 public static AsyncCallback AsyncCallback<T>(this Promise<T> that, Func<IAsyncResult,T> callback) {