public Promise <U> SelectWithCatch <U>(Func <T, U> selector) where U : class { var result = new Deferred <U>(); Done(t => { try { result.Resolve(selector(t)); } catch (Exception e) { result.Reject(e); } }); Fail(e => result.Reject(e)); Disposed(() => result.Dispose()); return(result); }
public override Promise <U> Then <U> ( Func <T, Promise <U> > done, Func <Exception, Promise <U> > fail, Func <Promise <U> > disposed) { var deferred = new Deferred <U>(); Done(t => { try { done(t) .Done(u => deferred.Resolve(u)) .Fail(e => deferred.Reject(e)) .Disposed(() => deferred.Dispose()); } catch (Exception e) { deferred.Reject(e); } }); Fail(e => { try { fail(e) .Done(u => deferred.Resolve(u)) .Fail(e2 => deferred.Reject(e2)) .Disposed(() => deferred.Dispose()); } catch (Exception exceptionFromFail) { deferred.Reject(exceptionFromFail); } }); Disposed(() => { try { disposed() .Done(u => deferred.Resolve(u)) .Fail(e => deferred.Reject(e)) .Disposed(() => deferred.Dispose()); } catch (Exception e) { deferred.Reject(e); } }); return(deferred); }
public static Promise <T> PropagateThrough <T>(this Promise <T> src, Deferred <T> dst) where T : class { dst.Propagate(src); return(src); }