Example #1
0
        public override Promise <U> Then <U> (Func <T, Promise <U> > done, Func <Exception, Promise <U> > fail)
        {
            if (this.IsDisposed)
            {
                return(Promises.Disposed <U>());
            }

            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(() => deferred.Dispose());
            return(deferred);
        }
Example #2
0
        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);
        }