43
I have an async predicate method like this:
private async Task<bool> MeetsCriteria(Uri address)
{
//Do something involving awaiting an HTTP request.
}
Say I have a collection of Uris:
var addresses = new[]
{
new Uri("http://www.google.com/"),
new Uri("http://www.stackoverflow.com/") //etc.
};
I want to filter addresses using MeetsCriteria. I want to do this asynchronously; I want multiple calls to the predicate to run asynchronously, and I want to then wait for all of them to complete and produce the filtered result set. Unfortunately, LINQ doesn't appear to support asynchronous predicates, so something like this doesn't work:
var filteredAddresses = addresses.Where(MeetsCriteria);
Is there a similarly convenient way to do this?