Skip to content

LINQ AsyncTaskExtensions

ZZZ Projects edited this page Jan 24, 2016 · 2 revisions

Async Task extension methods allow to perform operation on Task<IEnumerable<T>>.

// Using Z.Linq

public async Task<List<Customer>> MyAsyncTaskMethod(CancellationToken cancellationToken)
{
    // GET the five first customers which the predicate has completed
    var task = list.WhereAsync(c => MyAsyncPredicate(DB.IsCustomerActiveAsync(c)))
                         .OrderByPredicateCompletion()
                         .Take(5)
                         .ToList();


    // ... synchronous code ...
    
    return task;
}