runtime
runtime copied to clipboard
Linq support on Task
I think we should add linq support for IEnumerable<Task<T>> and Task<Enumerable<T>> with the same set of function as linq, let the lambda could return Task<T> and become unwrap while seamlessly handle both combination of IEnumerable<Task<T>> and Task<Enumerable<T>>
using System.Linq.Async;
////
// Enumerable of Task can Select, Where and any function supporterd by Linq
Task<IEnumerable<string>> texts = GetTask();
IEnumerable<Task<string[]>> tasks = task.ToEnumerablesTasks().Where((text) => text.Length > 10).Select((text) => text.Split(':'));
string[][] splits = await Task.WhenAll(tasks);
// Enumerable has extension method SelectAsync to create Enumerable of Task from lambda
IEnumerable<Task<DBObject>> tasks2 = splits.SelectAsync(async(split) => await QuerySomeDB(split[0],split[1]));
var result = await Task.WhenAll(tasks2);
If possible I would also want to have https://www.nuget.org/packages/System.Interactive.Async/ in BCL
ref dotnet/corefx#27084
We appreciate the suggestion, but we have no plans to do this. It's better handled by async enumerables, and if the task-based approach is really desired, it could be done just as well by any community-provided library.