We'll recap everything we've covered so far, and review today's agenda.
Promises can be thought of as "eventual values", and are a great abstraction of some asynchronous work. We'll review basic promise usage, error handling, and techniques for grouping promises together in sequence or in parallel.
Handling AsynchronyPROJECT: Fetch Coalescing
Often, when a single page app boots up, requests for remote data at various URLs will be sent out as part of the startup process. Occasionally, we can see multiple requests going out for the exact same resources. We'll build a utility that ensures that request for data that's already on its way are link together and resolved by the same promise.
Handling AsynchronyIterators and Generator Functions
Handling AsynchronyPROJECT: Async Task Runner
One of the most powerful things we can build on top of generator functions is an “async task runner”. You have an “autocomplete” use case already set up, that involves running several async operations in sequence.
Handling AsynchronyAsync and Await
Now that we’ve done all the work to build a task function, we’re in a perfect position to appreciate a new language feature that looks very similar:
awaitkeyword, when used in an
asyncfunction, allows us to write asynchronous code in a way that looks and feels very much like the synchronous (blocking) equivalent!
Handling AsynchronyEXERCISE: Write an Integration Test
Integration tests are a perfect place to use
await, because we often want to perform a series of simulated user interactions and wait for each one to complete, before proceeding further in the test.
Break for lunch