I'm using Flutter to download 3 different sets of data from a server, then do something with all 3 sets. I could do this:
List<Foo> foos = await downloader.getFoos();
List<Bar> bars = await downloader.getBars();
List<FooBars> foobars = await downloader.getFooBars();
processData(foos, bars, foobars);
But I'd prefer to download all 3 data sets asynchronously in parallel. I've seen that Dart has this Future.wait method:
Future<List<T>> wait <T>(
Iterable<Future<T>> futures, {
bool eagerError: false,
void cleanUp(
T successValue
)
})
However it looks like this will only return values of the same type (T). I have 3 different types, so I don't see how I can use this and get my 3 data sets back.
What's the best alternative way to achieve this?
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…