public static Aff <RT, Func <D, E> > Apply <RT, A, B, C, D, E>(this Func <A, B, C, D, E> f, Aff <RT, A> ma, Aff <RT, B> mb, Aff <RT, C> mc) where RT : struct, HasCancel <RT> =>
    AffMaybe <RT, Func <D, E> >(async rt =>
    {
        var(a, b, c) = await WaitAsync.WaitAll(ma.Run(rt), mb.Run(rt), mc.Run(rt)).ConfigureAwait(false);

        if (a.IsFail || b.IsFail || c.IsFail)
        {
            var errs = Errors.None;
            if (a.IsFail)
            {
                errs += a.Error;
            }
            if (b.IsFail)
            {
                errs += b.Error;
            }
            if (c.IsFail)
            {
                errs += c.Error;
            }
            return(errs);
        }
        else
        {
            return(FinSucc((D d) => f(a.Value, b.Value, c.Value, d)));
        }
    });
    public static Aff <D> Apply <A, B, C, D>(this Aff <Func <A, B, C, D> > mf, Aff <A> ma, Aff <B> mb, Aff <C> mc) =>
    AffMaybe <D>(async() =>
    {
        var(f, a, b, c) = await WaitAsync.WaitAll(mf.Run(), ma.Run(), mb.Run(), mc.Run()).ConfigureAwait(false);

        if (f.IsFail || a.IsFail || b.IsFail || c.IsFail)
        {
            var errs = Errors.None;
            if (f.IsFail)
            {
                errs += f.Error;
            }
            if (a.IsFail)
            {
                errs += a.Error;
            }
            if (b.IsFail)
            {
                errs += b.Error;
            }
            if (c.IsFail)
            {
                errs += c.Error;
            }
            return(errs);
        }
        else
        {
            return(f.Value(a.Value, b.Value, c.Value));
        }
    });
    public static Aff <RT, Func <C, D, E> > Apply <RT, A, B, C, D, E>(this Aff <RT, Func <A, B, C, D, E> > mf, Aff <RT, A> ma, Aff <RT, B> mb) where RT : struct, HasCancel <RT> =>
    AffMaybe <RT, Func <C, D, E> >(async rt =>
    {
        var(f, a, b) = await WaitAsync.WaitAll(mf.Run(rt), ma.Run(rt), mb.Run(rt)).ConfigureAwait(false);

        if (f.IsFail || a.IsFail || b.IsFail)
        {
            var errs = Errors.None;
            if (f.IsFail)
            {
                errs += f.Error;
            }
            if (a.IsFail)
            {
                errs += a.Error;
            }
            if (b.IsFail)
            {
                errs += b.Error;
            }
            return(errs);
        }
        else
        {
            return(FinSucc((C c, D d) => f.Value(a.Value, b.Value, c, d)));
        }
    });
    public static Aff <RT, E> Apply <RT, A, B, C, D, E>(this Aff <RT, Func <A, B, C, D, E> > mf, Aff <RT, A> ma, Aff <RT, B> mb, Aff <RT, C> mc, Aff <RT, D> md) where RT : struct, HasCancel <RT> =>
    AffMaybe <RT, E>(async rt =>
    {
        var(f, a, b, c, d) = await WaitAsync.WaitAll(mf.Run(rt), ma.Run(rt), mb.Run(rt), mc.Run(rt), md.Run(rt)).ConfigureAwait(false);

        if (f.IsFail || a.IsFail || b.IsFail || c.IsFail || d.IsFail)
        {
            var errs = Errors.None;
            if (f.IsFail)
            {
                errs += f.Error;
            }
            if (a.IsFail)
            {
                errs += a.Error;
            }
            if (b.IsFail)
            {
                errs += b.Error;
            }
            if (c.IsFail)
            {
                errs += c.Error;
            }
            if (d.IsFail)
            {
                errs += d.Error;
            }
            return(errs);
        }
        else
        {
            return(f.Value(a.Value, b.Value, c.Value, d.Value));
        }
    });
    public static Aff <Func <C, D, E> > Apply <A, B, C, D, E>(this Aff <Func <A, B, C, D, E> > mf, Aff <A> ma, Aff <B> mb) =>
    AffMaybe(async() =>
    {
        var(f, a, b) = await WaitAsync.WaitAll(mf.Run(), ma.Run(), mb.Run()).ConfigureAwait(false);

        if (f.IsFail || a.IsFail || b.IsFail)
        {
            var errs = Errors.None;
            if (f.IsFail)
            {
                errs += f.Error;
            }
            if (a.IsFail)
            {
                errs += a.Error;
            }
            if (b.IsFail)
            {
                errs += b.Error;
            }
            return(errs);
        }
        else
        {
            return(FinSucc((C c, D d) => f.Value(a.Value, b.Value, c, d)));
        }
    });
Ejemplo n.º 6
0
        public static async Task Condition(Func <Task <bool> > waitCondition,
                                           Func <WaitBuilderAsync <bool>, WaitAsync <bool> > buildWaiter,
                                           string timeoutMessage)
        {
            var waiter = WaitAsync <bool> .CreateBuilder(waitCondition);

            waiter.SetTimeOutMessage(timeoutMessage);
            await buildWaiter(waiter)
            .For(x => x).OnFailureThrowException();
        }
Ejemplo n.º 7
0
            protected override async Task OnRun_Async()
            {
                //打开Login界面
                await ViewManager.Instance.OpenAsync("KNFrame", View.State.Fixing);

                await WaitAsync.WaitForSeconds(1.0f);

                //隐藏进度条
                GameLoading.Instance.Hide();

                Debug.Log("GameStage -- Init data complete.");
            }
Ejemplo n.º 8
0
        /// <summary>
        /// 开始异步执行GameStage
        /// </summary>
        public async Task Run_Async()
        {
            for (int i = 0; i < taskList.Count; i++)
            {
                taskList[i].Run_Async().WarpErrors();
            }

            //等待这个索引的所有的Task执行完成后,才进入下一个索引
            while (!CheckStageIsCompleted())
            {
                await WaitAsync.WaitForEndOfFrame();
            }
            this.isStageCompleted = true;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 开始异步执行GameStage
        /// </summary>
        public async Task Run_Async()
        {
            for (int i = 0; i < taskList.Count; i++)
            {
                #pragma warning disable 4014
                taskList[i].Run_Async();
                #pragma warning restore 4014
            }

            //等待这个索引的所有的Task执行完成后,才进入下一个索引
            while (!CheckStageIsCompleted())
            {
                await WaitAsync.WaitForEndOfFrame();
            }
            this.isStageCompleted = true;
        }
    public static Aff <RT, C> Apply <RT, A, B, C>(this Func <A, B, C> f, Aff <RT, A> ma, Aff <RT, B> mb) where RT : struct, HasCancel <RT> =>
    AffMaybe <RT, C>(async rt =>
    {
        var(a, b) = await WaitAsync.WaitAll(ma.Run(rt), mb.Run(rt)).ConfigureAwait(false);

        if (a.IsFail || b.IsFail)
        {
            var errs = Errors.None;
            if (a.IsFail)
            {
                errs += a.Error;
            }
            if (b.IsFail)
            {
                errs += b.Error;
            }
            return(errs);
        }
        else
        {
            return(f(a.Value, b.Value));
        }
    });
    // ------------ Aff<RT, A> -----------------------------------------------------------------------------------------

    public static Aff <RT, B> Apply <RT, A, B>(this Aff <RT, Func <A, B> > mf, Aff <RT, A> ma) where RT : struct, HasCancel <RT> =>
    AffMaybe <RT, B>(async rt =>
    {
        var(f, a) = await WaitAsync.WaitAll(mf.Run(rt), ma.Run(rt)).ConfigureAwait(false);

        if (f.IsFail || a.IsFail)
        {
            var errs = Errors.None;
            if (f.IsFail)
            {
                errs += f.Error;
            }
            if (a.IsFail)
            {
                errs += a.Error;
            }
            return(errs);
        }
        else
        {
            return(f.Value(a.Value));
        }
    });
    public static Aff <Func <B, C, D> > Apply <A, B, C, D>(this Aff <Func <A, B, C, D> > mf, Aff <A> ma) =>
    AffMaybe(async() =>
    {
        var(f, a) = await WaitAsync.WaitAll(mf.Run(), ma.Run()).ConfigureAwait(false);

        if (f.IsFail || a.IsFail)
        {
            var errs = Seq <Error>();
            if (f.IsFail)
            {
                errs = errs.Add(f.Error);
            }
            if (a.IsFail)
            {
                errs = errs.Add(a.Error);
            }
            return(Error.Many(errs));
        }
        else
        {
            return(FinSucc((B b, C c) => f.Value(a.Value, b, c)));
        }
    });
    // ------------ Aff<A> ----------------------------------------------------------------------------------

    public static Aff <B> Apply <A, B>(this Aff <Func <A, B> > mf, Aff <A> ma) =>
    AffMaybe <B>(async() =>
    {
        var(f, a) = await WaitAsync.WaitAll(mf.Run(), ma.Run()).ConfigureAwait(false);

        if (f.IsFail || a.IsFail)
        {
            var errs = Errors.None;
            if (f.IsFail)
            {
                errs += f.Error;
            }
            if (a.IsFail)
            {
                errs += a.Error;
            }
            return(errs);
        }
        else
        {
            return(f.Value(a.Value));
        }
    });