Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        public void IntFutureSucessfull()
        {
            int ret = -1;

            IFuture <int> success = Future.Success(32);

            success.Map((x) => ret = x);

            Assert.AreEqual(32, ret);
        }
Ejemplo n.º 3
0
        public void IntFutureMapsToAfloatFutureRecoverPre()
        {
            bool called = false;

            IFuture <float> floatFuture = Future.Success(1.0f);

            floatFuture.Map((x) => { throw new Exception(); }).Recover((e) => { called = true; });

            Assert.That(called);
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
0
        public void IntFutureMapsToAfloatFuture()
        {
            float           ret         = -1;
            IFuture <float> floatFuture = m_future.Map((x) => x + 1.5f);

            floatFuture.Map((x) => ret = x);

            m_promise.Fulfill(32);

            Assert.Greater(ret, 32.0f);
        }
Ejemplo n.º 6
0
        public void IntFutureMapsToAfloatFutureRecover()
        {
            bool called = false;

            IFuture <float> floatFuture = m_future.Map((x) => x + 1.5f);

            floatFuture.Map((x) => { throw new Exception(); }).Recover((e) => { called = true; });

            m_promise.Fulfill(32);

            Assert.That(called);
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
        public void IntFutureMapPre()
        {
            int ret = -1;

            m_future.Map((x) => ret = x);
            m_promise.Fulfill(32);

            Assert.AreEqual(32, ret);
        }