zzzprojects / Linq Async
Labels
Projects that are alternatives of or similar to Linq Async
Library Powered By
This library is powered by Entity Framework Extensions
What's LINQ-Async?
LINQ-Async allows you to chain async task and order async predicate with fluent API.
Features
- LINQ Async Extensions
-
LINQ Async Precicate Extensions
- OrderByPredicateCompletion
- StartPredicateConcurrently
- LINQ Async Task Extensions
-
LINQ Async Enumerable Task Extensions
- OrderByCompletion
- SelectResult
Download
PM> Install-Package Z.Linq.Async
Stay updated with latest changes
LINQ Async Extensions
Problem
You want to use LINQ methods asynchronously.
Solution
All LINQ extensions methods and overloads are supported. You can easily create any asynchronous task.
// Using Z.Linq
public Task<IEnumerable<Customer>> MyAsyncMethod(CancellationToken cancellationToken)
{
List<Customer> customers = DB.GetCustomers();
var task = list.WhereAsync(c => /* long predicate */, cancellationToken);
// ... synchronous code ...
return task;
}
LINQ Async Predicate Extensions
Problem
You want to resolve a predicate asynchronously and start all predicates concurrently and/or order them by completion.
Solution
All LINQ extensions methods and overloads using a predicate is supported. You can easily use an asynchronously predicate and choose how the predicate will be resolved:
- OrderByPredicateCompletion(bool)
- StatePredicateConcurrently(bool)
Support:
- Deferred
- SkipWhile
- Where
- Immediate
- All
- Any
- Count
- First
- FirstOrDefault
- LongCount
- Single
- SingleOrDefault
// Using Z.Linq
// Change global default value
LinqAsyncManager.DefautlValue.OrderByPredicateCompletion = false;
LinqAsyncManager.DefaultValue.StartPredicateConcurrently = false;
public Task<IEnumerable<Customer>> MyAsyncTaskMethod(CancellationToken cancellationToken)
{
List<Customer> customers = DB.GetCustomers();
// GET all customers by predicate completion
var task = list.WhereAsync(c => MyAsyncPredicate(DB.IsCustomerActiveAsync(c)))
.OrderByPredicateCompletion();
// ... synchronous code ...
return task;
}
LINQ Async Task Extensions
Problem
You want to chain LINQ methods with Task<IEnumerable<T>>.
Solution
All LINQ extensions methods and overloads are supported, you can easily chain multiples LINQ methods before awaiting your final task.
Support:
- Array
- Enumerable
- List
Other types must use "AsEnumerable()" method to allow to chain LINQ methods.
// 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;
}
LINQ Async Enumerable Task Extensions
Problem
You want to use LINQ methods with enumerable task and order them by completion.
Solution
Support:
- OrderByCompletion
- SelectResult
// Using Z.Linq
public async Task<List<Customer>> MyAsyncTaskMethod(CancellationToken cancellationToken)
{
// GET customer from concurrent web service
IEnumerable<Task<List<Customer>>> task = WebService.GetCustomers();
// GET the customer list from the first web service completed
var taskFirstCompleted = task.SelectResultByCompletion()
.SelectResult()
.First()
// GET the five first customers which the predicate has completed
var task = taskFirstCompleted.WhereAsync(c => MyAsyncPredicate(DB.IsCustomerActiveAsync(c)))
.OrderByPredicateCompletion()
.Take(5)
.ToList();
// ... synchronous code ...
return task;
}
Contribute
You want to help us? Your donation directly helps us maintaining and growing ZZZ Free Projects. We can’t thank you enough for your support.
Why should I contribute to this free & open source library?
We all love free and open source libraries! But there is a catch! Nothing is free in this world. Contributions allow us to spend more of our time on: Bug Fix, Content Writing, Development and Support.
We NEED your help. Last year alone, we spent over 3000 hours maintaining all our open source libraries.
How much should I contribute?
Any amount is much appreciated. All our libraries together have more than 100 million downloads, if everyone could contribute a tiny amount, it would help us to make the .NET community a better place to code!
Another great free way to contribute is spreading the word about the library!
A HUGE THANKS for your help.
More Projects
- EntityFramework Extensions
- Dapper Plus
- C# Eval Expression
- and much more! To view all our free and paid librariries visit our website.