public static IEnumerableAsync <Func <T, Task> > AsEnumerableAsync <T>(this IEnumerable <T> items) { return(EnumerableAsync.YieldAsync <Func <T, Task> >( async(yieldAsync) => { await items.ForYield(yieldAsync); })); }
public static IEnumerableAsync <T> PrespoolAsync <T>(this IEnumerableAsync <T> items) { var iterator = items.GetIterator(); var queue = new ConcurrentQueue <Func <T, Task> >(); var totalExpression = GetTotalExpression <T>(); var basicExpression = totalExpression(queue); var iterationTask = iterator.IterateAsync(basicExpression); return(EnumerableAsync.YieldAsync <T>( async(yieldAsync) => { while (!iterationTask.IsCompleted || queue.Count() > 0) { Func <T, Task> callback; if (queue.TryDequeue(out callback)) { await callback(yieldAsync); } } })); }