group method
Executes a group of API requests concurrently and returns their responses.
The method takes a list of Future API requests and waits for all of them to complete. The responses are then returned as a list in the same order as the input requests.
Example:
List<Future<Response>> requests = [
api.get('/endpoint1'),
api.get('/endpoint2'),
];
List<Response> responses = await apiServices.group(requests);
requests: A list of Future<Response> objects representing the API requests.
Implementation
Future<List<Response>> group(List<Future<Response>> requests) async {
List<Response> responses = [];
await Future.forEach(requests, (req) async {
final res = await req;
responses.add(res);
});
return responses;
}