A dashboard may need an order count and a notification count. When neither depends on the other’s result, start both before waiting. Keep the failure contract clear: a page that needs every result differs from one that can render partial data.
Worked example
Language requirement: Dart 3.0 or later. This complete example uses browser-supported libraries.
Future<int> loadOrders() async {
await Future<void>.delayed(const Duration(milliseconds: 30));
return 12;
}
Future<int> loadAlerts() async {
await Future<void>.delayed(const Duration(milliseconds: 10));
return 3;
}
Future<void> main() async {
final orders = loadOrders();
final alerts = loadAlerts();
final results = await Future.wait([orders, alerts])
.timeout(const Duration(seconds: 1));
print('Orders: ${results[0]}; alerts: ${results[1]}');
}Follow the data and control flow
Calling the loaders starts both asynchronous operations. Future.wait returns results in input order, not completion order, so the faster alert result remains in position one. The timeout limits how long this caller waits for the combined result.
The underlying operations are not automatically cancelled when a timeout occurs. A provider may expose its own cancellation mechanism. With heterogeneous results, use a typed contract instead of relying on several dynamic list positions. Consider named records or an application-specific result model.
A mistake to avoid
Launching thousands of futures at once can overload a service or exhaust connections. Add bounded concurrency for large batches. Also avoid blindly retrying a timed-out non-idempotent request: the server may already have completed it even though the client stopped waiting.
Practice and verification
Make one loader fail and observe the combined failure. Design a partial-success dashboard where the other result remains useful. Write down which requests are safe to retry and where cancellation would be implemented for a real HTTP client.