How to Cancel Future.wait in Flutter: Parallel Async Done Right

Stop awaiting in a loop. Learn how to cancel Future.wait in Flutter, run async tasks in parallel, handle partial failures safely — and when not to parallelize.

If you await three network calls one after another, you wait for all three durations added together — even though none of them depends on the others. That serial habit is the most common performance bug in async Dart, and the fix is one line: Future.wait . In this guide you'll see a timed before/after, learn eagerError and cleanUp , handle partial failures without losing everything — and since Dart futures can't truly be cancelled, you'll learn exactly how to cancel a Future.wait in practice: stop waiting, ignore stale results, and reach for CancelableOperation when you need real cancellation. What you'll learn Why await in a loop is serial (and how slow that gets) Future.wait for parallel execution, with a Stopwatch comparison eagerError and cleanUp : what really happens when one task fails The "safe wrapper" pattern for partial failures (a sealed Result type) Future.wait vs FutureGroup from package:async When NOT to parallelize Step 1 — The serial problem (measure it) Three "endpoints", each taking about a second. Awaited one after another: /// Fake endpoint: takes [seconds] to respond. Future<String> fetchEndpoint(String name, int seconds) async { await Future.delayed(Duration(seconds: seconds)); return 'data-from-$name'; } Future<void> main() async { final sw = Stopwatch()..start(); final users = await fetchEndpoint('users', 1); // waits ~1s final posts = await fetchEndpoint('posts', 1); // waits ~1s more final comments = await fetchEndpoint('comments', 1); // waits ~1s more print('Sequential: ${sw.elapsedMilliseconds}ms'); print(' $users, $posts, $comments'); } Run it with dart run : roughly 3000ms . The key insight: fetchEndpoint('posts', 1) isn't even called until users completes. Nothing about these three calls depends on each other, so that serialization is…

Explore