예제 #1
0
        public static async ETTask <bool> WaitAny(ETTask[] tasks, ETCancellationToken cancellationToken = null)
        {
            if (tasks.Length == 0)
            {
                return(false);
            }

            CoroutineBlocker coroutineBlocker = new CoroutineBlocker(2);

            foreach (ETTask task in tasks)
            {
                RunOneTask(task).Coroutine();
            }

            async ETVoid RunOneTask(ETTask task)
            {
                await task;
                await coroutineBlocker.WaitAsync();
            }

            await coroutineBlocker.WaitAsync();

            if (cancellationToken == null)
            {
                return(true);
            }

            return(!cancellationToken.IsCancel());
        }
예제 #2
0
        public static async ETTask <bool> WaitAll(List <ETTask> tasks, ETCancellationToken cancellationToken = null)
        {
            if (tasks.Count == 0)
            {
                return(false);
            }

            CoroutineBlocker coroutineBlocker = new CoroutineBlocker(tasks.Count + 1);

            foreach (ETTask task in tasks)
            {
                RunOneTask(task).Coroutine();
            }

            await coroutineBlocker.WaitAsync();

            async ETVoid RunOneTask(ETTask task)
            {
                await task;
                await coroutineBlocker.WaitAsync();
            }

            if (cancellationToken == null)
            {
                return(true);
            }

            return(!cancellationToken.IsCancel());
        }