Exemple #1
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));
        }
Exemple #2
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));
        }
Exemple #3
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 FulfillError(object e)
        {
            ThrowIfCantFulfill();

            m_future.FlushErrorRecover(e);
        }