Chapter 15 — Asynchronous Programming: Future, async, await
Part 1A — Learn Dart · Chapter 15 of 62 · 6 h
Chapter 15 — Asynchronous Programming: Future, async, await
Level: intermediate Estimated duration: 6 h Prerequisites: Chapter 13 — Exceptions and Error Handling, Chapter 14 — Functional Programming on Collections What you will be able to do by the end: write a program that waits for a long-running result (loading, network, file) without ever blocking the rest of the application, using
Future,async,await,Future.wait(), andStream.
15.0 — Chapter Objectives
By the end of this chapter, you will be able to:
- explain why a long-running operation must never block the program;
- distinguish synchronous processing from asynchronous processing;
- explain what Dart's event loop is and why Dart is single-threaded;
- predict the actual output order of an asynchronous program;
- define a
Futureand name its three states; - create a
FuturewithFuture.delayed(),Future.value(), andFuture.error(); - use
.then(),.catchError(), and.whenComplete(); - write an
asyncfunction and useawait; - understand why an
asyncfunction always returns aFuture; - catch an asynchronous error with
try/catch/finally; - recognize needlessly sequential
awaitcalls and parallelize them withFuture.wait(); - use
unawaitedfor a future that is intentionally not awaited; - write an asynchronous
main(); - explain the difference between a
Futureand aStream; - produce a
Streamwithasync*andyield; - consume a
Streamwithawait forand withlisten(); - transform a
Streamwithmapandwhere; - explain why Flutter relies entirely on asynchronous programming.
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion