Exemple #1
0
 /// <summary>
 /// Runs a coroutine then runs the next queued coroutine (via <see cref="Run"/>) if available.
 /// Increments <see cref="numActive"/> before running the coroutine and decrements it after.
 /// </summary>
 /// <returns>Values yielded by the given coroutine</returns>
 /// <param name="coroutine">Coroutine to run</param>
 private IEnumerator CoroutineRunner(IEnumerator coroutine)
 {
     numActive++;
     while (coroutine.MoveNext())
     {
         yield return(coroutine.Current);
     }
     numActive--;
     if (queue.Count > 0)
     {
         var next = queue.Dequeue();
         _Run(next);
     }
     else
     {
         if (numActive == 0 && mode == QueueMode.BATCH)
         {
             OnBatchComplete?.Invoke();
             mode = QueueMode.SINGLE;
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Main method - run the batch
        /// </summary>
        /// <returns></returns>
        public async Task Run()
        {
            foreach (object item in Items)
            {
                // Await all file reads
                object result = await BatchSingle(item);

                // Check completion
                Completed++;

                BatchCompletedEventArgs frea = new BatchCompletedEventArgs()
                {
                    Result = result
                };
                OnProcessComplete?.Invoke(this, frea);

                if (Completed == Amount)
                {
                    frea = new BatchCompletedEventArgs();
                    OnBatchComplete?.Invoke(this, frea);
                }
            }
        }