##// END OF EJS Templates
Bound promise to CancellationToken...
cin -
r209:a867536c68fc v2
parent child
Show More
@@ -13,6 +13,12
13
13
14 Running,
14 Running,
15
15
16 Suspending,
17
18 Suspended,
19
20 Resuming,
21
16 Stopping,
22 Stopping,
17
23
18 Failed,
24 Failed,
@@ -263,6 +263,8 namespace Implab {
263
263
264 public static IPromise<T2> Then<T, T2>(this IPromise<T> that, Func<T, T2> success, Func<Exception, T2> error, Func<Exception, T2> cancel) {
264 public static IPromise<T2> Then<T, T2>(this IPromise<T> that, Func<T, T2> success, Func<Exception, T2> error, Func<Exception, T2> cancel) {
265 Safe.ArgumentNotNull(that, "that");
265 Safe.ArgumentNotNull(that, "that");
266 Safe.ArgumentNotNull(success, "success");
267
266 var d = new FuncTask<T, T2>(success, error, cancel, false);
268 var d = new FuncTask<T, T2>(success, error, cancel, false);
267 that.On(d.Resolve, d.Reject, d.CancelOperation);
269 that.On(d.Resolve, d.Reject, d.CancelOperation);
268 d.CancellationRequested(that.Cancel);
270 d.CancellationRequested(that.Cancel);
@@ -427,6 +429,13 namespace Implab {
427
429
428 #endregion
430 #endregion
429
431
432 public static IPromise<T2> Guard<T, T2>(this IPromise<T> that, Func<IPromise<T>, IPromise<T2>> continuation, Action<T> cleanup) {
433 Safe.ArgumentNotNull(that, "that");
434 Safe.ArgumentNotNull(continuation, "continuation");
435 return continuation(that).Error((err) => {
436 that.On(cleanup);
437 }, true);
438 }
430
439
431 #if NET_4_5
440 #if NET_4_5
432
441
@@ -442,6 +451,24 namespace Implab {
442 return new PromiseAwaiter(that);
451 return new PromiseAwaiter(that);
443 }
452 }
444
453
454 public static IPromise BoundCancellationToken(this IPromise that, CancellationToken ct) {
455 Safe.ArgumentNotNull(that, "that");
456 ct.Register(that.Cancel);
457 return that.Then(null, null, (err) => {
458 ct.ThrowIfCancellationRequested();
459 throw new PromiseTransientException(err);
460 });
461 }
462
463 public static IPromise<T> BoundCancellationToken<T>(this IPromise<T> that, CancellationToken ct) {
464 Safe.ArgumentNotNull(that, "that");
465 ct.Register(that.Cancel);
466 return that.Then(null, null, (err) => {
467 ct.ThrowIfCancellationRequested();
468 throw new PromiseTransientException(err);
469 });
470 }
471
445 #endif
472 #endif
446 }
473 }
447 }
474 }
@@ -127,5 +127,6 namespace Implab
127 return Promise<T>.FromException(err);
127 return Promise<T>.FromException(err);
128 }
128 }
129 }
129 }
130
130 }
131 }
131 }
132 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

ok, latest stable version should be in default

You need to be logged in to leave comments. Login now