//   并行执行任务扩展
        internal static async Task <GroupExecuteResp <TTData, TTRes> > Executing_Parallel <TTData, TTRes>(this IList <BaseEventTask <TTData, TTRes> > tasks, TTData data)
            where TTData : class
        //where TTRes : class, new()
        {
            var taskHandlers =
                tasks.ToDictionary(t => t, t => GroupExecutorUtil.TryGetTaskItemResult(data, t));

            await Task.WhenAll(taskHandlers.Select(tr => tr.Value));


            var taskResps = taskHandlers.ToDictionary(d => d.Key, d => d.Value.Result);

            GroupExecuteStatus exeStatus = 0;

            foreach (var eventTaskResp in taskResps)
            {
                var s = GroupExecutorUtil.FormatEffectStatus(eventTaskResp.Value);
                exeStatus |= s;
            }

            return(new GroupExecuteResp <TTData, TTRes>()
            {
                status = exeStatus,
                TaskResults = taskResps
            });
        }
Exemple #2
0
        ///  顺序执行
        internal static async Task <GroupExecuteResp <TTData, TTRes> > Executing_Serial <TTData, TTRes>(this IList <BaseEventTask <TTData, TTRes> > tasks, TTData data)
            where TTData : class
        //where TTRes : class, new()
        {
            var exeResp = new GroupExecuteResp <TTData, TTRes>
            {
                TaskResults = new Dictionary <BaseEventTask <TTData, TTRes>, EventTaskResp <TTRes> >(tasks.Count)
            };

            foreach (var tItem in tasks)
            {
                var taskResp = await GroupExecutorUtil.TryGetTaskItemResult(data, tItem);

                exeResp.TaskResults.Add(tItem, taskResp);
                exeResp.status |= GroupExecutorUtil.FormatEffectStatus(taskResp);

                if ((exeResp.status & GroupExecuteStatus.Failed) == GroupExecuteStatus.Failed)
                {
                    return(exeResp);
                }
            }

            return(exeResp);
        }