Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

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);

Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #async #linq
ADD COMMENT
Topic
Name
4+5 =