Пример #1
0
        static ChildFunc Create()
        {
            var f = LeanClassPool <ChildFunc> .Spawn();

            if (f == null)
            {
                f = new ChildFunc();
            }

            return(f);
        }
Пример #2
0
        override internal void Execute(object[] args)
        {
            if (args.Length != 3)
            {
                throw new ArgumentException();
            }

            if (!(args [0] is IEnumerable <T>))
            {
                throw new ArgumentException();
            }

            if (args [1] == null || !(args [1] is ChildFunc <T>))
            {
                throw new ArgumentException();
            }

            if (args [args.Length - 1] == null || !(args [args.Length - 1] is UAsyncFinalFunc))
            {
                throw new ArgumentException();
            }

            IsDone      = false;
            IsFree      = false;
            completeNum = 0;
            var temp = (IEnumerable <T>)args [0];

            items.Clear();
            items.AddRange(temp.ToList());
            total     = items.Count;
            finalFunc = args [args.Length - 1] as UAsyncFinalFunc;

            if (total == 0)
            {
                IsDone = true;
                IsFree = true;
                finalFunc.action2(null);
                return;
            }

            func = args [1] as ChildFunc <T>;
            RunOneFunc();
        }
Пример #3
0
        void RunOneFunc(ChildFunc func)
        {
            var name = func.name;

            if (func.action2 != null)
            {
                taskRoutine =
                    TaskRunner.Instance.Run(
                        new SingleTask(
                            () => func.action2((err, res) => Callback(name, err, res), result)),
                        TaskRunnerCallback
                        );
            }
            else
            {
                taskRoutine =
                    TaskRunner.Instance.Run(
                        func.enumerator2((err, res) => Callback(name, err, res), result),
                        TaskRunnerCallback);
            }
        }
Пример #4
0
        internal override void Execute(object[] args)
        {
            if (args.Length != 3)
            {
                throw new ArgumentException();
            }

            if (!(args [0] is IEnumerable <T>))
            {
                throw new ArgumentException();
            }

            if (args [1] == null || !(args [1] is ChildFunc <T>))
            {
                throw new ArgumentException();
            }

            if (args [args.Length - 1] == null || !(args [args.Length - 1] is UAsyncFinalFunc))
            {
                throw new ArgumentException();
            }

            IsDone      = false;
            IsFree      = false;
            completeNum = 0;
            var temp = (IEnumerable <T>)args [0];

            items.Clear();
            items.AddRange(temp.ToList());
            total     = items.Count;
            finalFunc = args [args.Length - 1] as UAsyncFinalFunc;

            if (total == 0)
            {
                IsDone = true;
                IsFree = true;
                finalFunc.action2(null);
                return;
            }

            taskRoutines.Clear();
            func = args [1] as ChildFunc <T>;

            for (var i = 0; i < total; i++)
            {
                var item = items [i];

                if (func.action1 != null)
                {
                    taskRoutines.Add(
                        TaskRunner.Instance.Run(
                            new SingleTask(() => func.action1(item, Callback)),
                            TaskRunnerCallback)
                        );
                }
                else
                {
                    taskRoutines.Add(
                        TaskRunner.Instance.Run(
                            func.enumerator1(item, Callback),
                            TaskRunnerCallback)
                        );
                }
            }
        }