##// END OF EJS Templates
Bound promise to CancellationToken...
cin -
r209:a867536c68fc v2
parent child
Show More
@@ -13,6 +13,12
13 13
14 14 Running,
15 15
16 Suspending,
17
18 Suspended,
19
20 Resuming,
21
16 22 Stopping,
17 23
18 24 Failed,
@@ -180,8 +180,8 namespace Implab {
180 180 /// <param name="cleanup">A callback used to cleanup already resolved promises in case of an error</param>
181 181 /// <returns></returns>
182 182 public static IPromise<T[]> PromiseAll<T>(this ICollection<IPromise<T>> that, Action<T> cleanup) {
183 Safe.ArgumentNotNull(that, "that");
184
183 Safe.ArgumentNotNull(that, "that");
184
185 185 int count = that.Count;
186 186
187 187 if (count == 0)
@@ -263,6 +263,8 namespace Implab {
263 263
264 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 265 Safe.ArgumentNotNull(that, "that");
266 Safe.ArgumentNotNull(success, "success");
267
266 268 var d = new FuncTask<T, T2>(success, error, cancel, false);
267 269 that.On(d.Resolve, d.Reject, d.CancelOperation);
268 270 d.CancellationRequested(that.Cancel);
@@ -276,8 +278,8 namespace Implab {
276 278 success(x);
277 279 return x;
278 280 },
279 error,
280 cancel,
281 error,
282 cancel,
281 283 false
282 284 );
283 285 that.On(d.Resolve, d.Reject, d.CancelOperation);
@@ -427,6 +429,13 namespace Implab {
427 429
428 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 440 #if NET_4_5
432 441
@@ -442,6 +451,24 namespace Implab {
442 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 472 #endif
446 473 }
447 474 }
@@ -127,5 +127,6 namespace Implab
127 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