Answers for "async where linq"

C#
0

async where linq

static async Task<IEnumerable<T>> Where<T>(
    this IEnumerable<T> source, Func<T, Task<bool>> predicate)
{
    var results = new ConcurrentQueue<T>();
    var tasks = source.Select(
        async x =>
        {
            if (await predicate(x))
                results.Enqueue(x);
        });
    await Task.WhenAll(tasks);
    return results;
}


var filteredAddresses = await addresses.Where(MeetsCriteria);
Posted by: Guest on November-23-2020

C# Answers by Framework

Browse Popular Code Answers by Language