runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Linq support on Task

Open Thaina opened this issue 8 years ago • 2 comments

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

Thaina avatar Feb 13 '18 05:02 Thaina

ref dotnet/corefx#27084

ichensky avatar Feb 06 '19 12:02 ichensky

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.

stephentoub avatar Jul 18 '19 15:07 stephentoub