public static Task Run(IEnumerable <Task> iterator, CancellationToken cancellationToken)
 {
     // WARNING: This code uses LINQ Select to ensure that we get deferred execution (i.e., we
     // don't start running all the tasks all at once). If you touch this code, please ensure
     // that this behavior is preserved.
     return(IterateEngine <AsyncVoid> .Run(iterator.Select(t => t.ToTask <AsyncVoid>()), cancellationToken));
 }
        /// <summary>
        /// Return a task that runs all the tasks inside the iterator sequentially. It stops as soon
        /// as one of the tasks fails or cancels, or after all the tasks have run succesfully.
        /// </summary>
        /// <param name="asyncIterator">collection of tasks to wait on</param>
        /// <param name="cancellationToken">cancellation token</param>
        /// <returns>a task that signals completed when all the incoming tasks are finished.</returns>
        internal static Task Iterate(IEnumerable <Task> asyncIterator, CancellationToken cancellationToken = default(CancellationToken))
        {
            Contract.Assert(asyncIterator != null);

            return(IterateEngine.Run(asyncIterator, cancellationToken));
        }