Example #1
0
        /// <summary>
        /// Executes, in parallel chunks, an enumerator function for every element in the given list.
        /// </summary>
        static public IEnumerator ForEachParallel <T>(IList <T> inList, Func <T, IEnumerator> inOperation, int inChunkSize)
        {
            int count = 0;

            if (inList != null && inOperation != null && (count = inList.Count) > 0)
            {
                int           chunkSize   = Math.Min(inChunkSize, count);
                int           numItems    = 0;
                IEnumerator[] enumerators = new IEnumerator[chunkSize];
                for (int i = 0; i < count; ++i)
                {
                    enumerators[numItems++] = inOperation(inList[i]);
                    if (i == count - 1 || numItems == chunkSize)
                    {
                        yield return(Routine.Inline(
                                         Routine.Combine(enumerators)
                                         ));

                        for (int j = 0; j < numItems; ++j)
                        {
                            enumerators[j] = null;
                        }
                        numItems = 0;
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Executes, in parallel, an enumerator function for every element in the given list.
        /// </summary>
        static public IEnumerator ForEachParallel <T>(IList <T> inList, Func <T, IEnumerator> inOperation)
        {
            int count = 0;

            if (inList != null && inOperation != null && (count = inList.Count) > 0)
            {
                IEnumerator[] enumerators = new IEnumerator[count];
                for (int i = 0; i < count; ++i)
                {
                    enumerators[i] = inOperation(inList[i]);
                }
                yield return(Routine.Inline(
                                 Routine.Combine(enumerators)
                                 ));
            }
        }
Example #3
0
 /// <summary>
 /// Executes the routines in parallel.
 /// </summary>
 public Sequence Combine(params IEnumerator[] inNexts)
 {
     AddNode(NodeType.Routine, Routine.Combine(inNexts));
     return(this);
 }