The Quiver package contains several functions to iterate with async.
doWhileAsync
,reduceAsync
andforEachAsync
perform async computations on the elements of on Iterables, waiting for the computation to complete before processing the next element.
doWhileAsync seems to be exactly what is wanted :
List<String> urls = [/*...*/];
doWhileAsync(urls, (url) => getContent(url).then((content) {
if (!matchCriteria(content)) {
return new Future.value(true); // try with next url
} else {
doSomethingIfMatch();
return new Future.value(false);
}
}));