public static async Task ForEach <T>(this ITaskEnumerable <T> source, Action <T, ITaskForEachController> action) { if (source == null || action == null) { return; } var controller = new TaskForEachController(); using (var iterator = source.GetEnumerator()) { while (iterator.MoveNext()) { if (controller.CheckContinue()) { continue; } var item = await iterator.Current; action(await iterator.Current, controller); if (controller.CheckBreak()) { break; } } } }
public IEnumerator <Task <TResult> > GetEnumerator() { using (var iterator = source.GetEnumerator()) { var continuation = this.continuation; while (iterator.MoveNext()) { yield return(continuation(iterator.Current)); } } }