示例#1
0
        public static IFuture <K> Recover <T, K, W>(this IFuture <T> me, Func <W, K> recoverFunc)  // where T:K
        {
            InnerFuture other = new InnerFuture();

            me.Recover((W e) => { other.Set(recoverFunc(e)); });
            me.Map((val) => { other.Set(val); });

            return(new FutureWrapper <K>(other));
        }
示例#2
0
        public static IFuture <T> Success <T>(T value)
        {
            InnerFuture inner = new InnerFuture();

            inner.Set(value);

            return(new FutureWrapper <T>(inner));
        }
示例#3
0
        public static IFuture <K> FlatMap <T, K> (this IFuture <T> me, System.Func <T, IFuture <K> > flatMapFunc)
        {
            InnerFuture other = new InnerFuture();

            me.Map((x) => {
                var map1 = flatMapFunc(x).Map((k) => other.Set(k));
                return(map1.Recover((e) => other.FlushErrorRecover(e)));
            }).Recover((e) => other.FlushErrorRecover(e));

            return(new FutureWrapper <K>(other));
        }
示例#4
0
        public static IFuture <K> FlatRecover <T, K, W>(this IFuture <T> me, Func <W, IFuture <K> > recoverFunc) where T : K
        {
            InnerFuture other = new InnerFuture();

            me.Recover((W e) =>
            {
                var future = recoverFunc(e);
                future.Map((x) => other.Set(x));
                future.Recover((e2) => other.FlushErrorRecover(e2));
            });

            me.Recover((object e) => {
                if (!(e is W))
                {
                    other.FlushErrorRecover(e);
                }
            });

            me.Map((val) => { other.Set(val); });

            return(new FutureWrapper <K>(other));
        }
示例#5
0
        public InnerFuture Map(Func <object, object> mapFunc)
        {
            if (IsDisposed)
            {
                throw new FutureContentDisposed();
            }

            InnerFuture other = new InnerFuture();

            if (Error != null)
            {
                other.FlushErrorRecover(Error);
                return(other);
            }

            m_mapFunc += (x) =>
            {
                try
                {
                    other.Set(mapFunc(x));
                }
                catch (System.Exception e)
                {
                    other.FlushErrorRecover(e);
                }
            };

            if (IsSet == true)
            {
                FlushMapFunc();
            }

            Recover((object e) => other.FlushErrorRecover(e), typeof(object));

            return(other);
        }
        public void Fulfill(T val)
        {
            ThrowIfCantFulfill();

            m_future.Set(val);
        }