Mercurial > pub > ImplabNet
comparison Implab/PromiseExtensions.cs @ 149:eb793fbbe4ea v2
fixed promises cancellation
| author | cin |
|---|---|
| date | Wed, 06 May 2015 17:11:27 +0300 |
| parents | 706fccb85524 |
| children | ec91a6dfa5b3 |
comparison
equal
deleted
inserted
replaced
| 148:e6d4b41f0101 | 149:eb793fbbe4ea |
|---|---|
| 176 } | 176 } |
| 177 | 177 |
| 178 public static IPromise Then(this IPromise that, Action success, Action<Exception> error, Action<Exception> cancel) { | 178 public static IPromise Then(this IPromise that, Action success, Action<Exception> error, Action<Exception> cancel) { |
| 179 Safe.ArgumentNotNull(that, "that"); | 179 Safe.ArgumentNotNull(that, "that"); |
| 180 | 180 |
| 181 var d = new ActionTask(success, error, cancel); | 181 var d = new ActionTask(success, error, cancel, false); |
| 182 that.On(d.Resolve, d.Reject, d.CancelOperation); | 182 that.On(d.Resolve, d.Reject, d.CancelOperation); |
| 183 if (success != null) | 183 if (success != null) |
| 184 d.CancellationRequested(that.Cancel); | 184 d.CancellationRequested(that.Cancel); |
| 185 return d; | 185 return d; |
| 186 } | 186 } |
| 194 } | 194 } |
| 195 | 195 |
| 196 public static IPromise<T> Then<T>(this IPromise that, Func<T> success, Func<Exception, T> error, Func<Exception, T> cancel) { | 196 public static IPromise<T> Then<T>(this IPromise that, Func<T> success, Func<Exception, T> error, Func<Exception, T> cancel) { |
| 197 Safe.ArgumentNotNull(that, "that"); | 197 Safe.ArgumentNotNull(that, "that"); |
| 198 | 198 |
| 199 var d = new FuncTask<T>(success, error, cancel); | 199 var d = new FuncTask<T>(success, error, cancel, false); |
| 200 that.On(d.Resolve, d.Reject, d.CancelOperation); | 200 that.On(d.Resolve, d.Reject, d.CancelOperation); |
| 201 if (success != null) | 201 if (success != null) |
| 202 d.CancellationRequested(that.Cancel); | 202 d.CancellationRequested(that.Cancel); |
| 203 return d; | 203 return d; |
| 204 } | 204 } |
| 211 return Then(that, success, null, null); | 211 return Then(that, success, null, null); |
| 212 } | 212 } |
| 213 | 213 |
| 214 public static IPromise<T2> Then<T, T2>(this IPromise<T> that, Func<T, T2> success, Func<Exception, T2> error, Func<Exception, T2> cancel) { | 214 public static IPromise<T2> Then<T, T2>(this IPromise<T> that, Func<T, T2> success, Func<Exception, T2> error, Func<Exception, T2> cancel) { |
| 215 Safe.ArgumentNotNull(that, "that"); | 215 Safe.ArgumentNotNull(that, "that"); |
| 216 var d = new FuncTask<T,T2>(success, error, cancel); | 216 var d = new FuncTask<T,T2>(success, error, cancel, false); |
| 217 that.On(d.Resolve, d.Reject, d.CancelOperation); | 217 that.On(d.Resolve, d.Reject, d.CancelOperation); |
| 218 if (success != null) | 218 if (success != null) |
| 219 d.CancellationRequested(that.Cancel); | 219 d.CancellationRequested(that.Cancel); |
| 220 return d; | 220 return d; |
| 221 } | 221 } |
| 230 | 230 |
| 231 #region chain traits | 231 #region chain traits |
| 232 public static IPromise Chain(this IPromise that, Func<IPromise> success, Func<Exception,IPromise> error, Func<Exception,IPromise> cancel) { | 232 public static IPromise Chain(this IPromise that, Func<IPromise> success, Func<Exception,IPromise> error, Func<Exception,IPromise> cancel) { |
| 233 Safe.ArgumentNotNull(that, "that"); | 233 Safe.ArgumentNotNull(that, "that"); |
| 234 | 234 |
| 235 var d = new ActionChainTask(success, error, cancel); | 235 var d = new ActionChainTask(success, error, cancel, false); |
| 236 that.On(d.Resolve, d.Reject, d.CancelOperation); | 236 that.On(d.Resolve, d.Reject, d.CancelOperation); |
| 237 if (success != null) | 237 if (success != null) |
| 238 d.CancellationRequested(that.Cancel); | 238 d.CancellationRequested(that.Cancel); |
| 239 return d; | 239 return d; |
| 240 } | 240 } |
| 248 } | 248 } |
| 249 | 249 |
| 250 public static IPromise<T> Chain<T>(this IPromise that, Func<IPromise<T>> success, Func<Exception, IPromise<T>> error, Func<Exception, IPromise<T>> cancel) { | 250 public static IPromise<T> Chain<T>(this IPromise that, Func<IPromise<T>> success, Func<Exception, IPromise<T>> error, Func<Exception, IPromise<T>> cancel) { |
| 251 Safe.ArgumentNotNull(that, "that"); | 251 Safe.ArgumentNotNull(that, "that"); |
| 252 | 252 |
| 253 var d = new FuncChainTask<T>(success, error, cancel); | 253 var d = new FuncChainTask<T>(success, error, cancel, false); |
| 254 that.On(d.Resolve, d.Reject, d.CancelOperation); | 254 that.On(d.Resolve, d.Reject, d.CancelOperation); |
| 255 if (success != null) | 255 if (success != null) |
| 256 d.CancellationRequested(that.Cancel); | 256 d.CancellationRequested(that.Cancel); |
| 257 return d; | 257 return d; |
| 258 } | 258 } |
| 265 return Chain(that, success, null, null); | 265 return Chain(that, success, null, null); |
| 266 } | 266 } |
| 267 | 267 |
| 268 public static IPromise<T2> Chain<T, T2>(this IPromise<T> that, Func<T, IPromise<T2>> success, Func<Exception, IPromise<T2>> error, Func<Exception, IPromise<T2>> cancel) { | 268 public static IPromise<T2> Chain<T, T2>(this IPromise<T> that, Func<T, IPromise<T2>> success, Func<Exception, IPromise<T2>> error, Func<Exception, IPromise<T2>> cancel) { |
| 269 Safe.ArgumentNotNull(that, "that"); | 269 Safe.ArgumentNotNull(that, "that"); |
| 270 var d = new FuncChainTask<T,T2>(success, error, cancel); | 270 var d = new FuncChainTask<T,T2>(success, error, cancel, false); |
| 271 that.On(d.Resolve, d.Reject, d.CancelOperation); | 271 that.On(d.Resolve, d.Reject, d.CancelOperation); |
| 272 if (success != null) | 272 if (success != null) |
| 273 d.CancellationRequested(that.Cancel); | 273 d.CancellationRequested(that.Cancel); |
| 274 return d; | 274 return d; |
| 275 } | 275 } |
