/// <summary> /// Asynchronously iterates over the input sequence and performs the specified action on each element of the <see cref="IAsyncQueryable{T}"/>. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <param name="source">An <see cref="IAsyncQueryable{T}"/> containing items to operate on.</param> /// <param name="action">The action to perform on each element.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception> public static Task ForEachAsync <TSource>(this IAsyncQueryable <TSource> source, Action <TSource> action, CancellationToken cancellationToken = default(CancellationToken)) { if (action == null) { throw new ArgumentNullException(nameof(action)); } return(source.ForEachAsync( item => { action(item); return false; }, cancellationToken)); }