Module lessons (2/3)
Typed Concurrency: Promise.all, allSettled and race
Take advantage of the tuple inference of Promise.all and manage partial outcomes with PromiseSettledResult<T>.
What you'll learn in this lesson
- Leverage heterogeneous tuple inference of
Promise.all([pA, pB])to obtain distinct types for each element. - Include the discriminated union
PromiseSettledResult<T>inPromise.allSettledand filter the results withstatus === 'fulfilled'. - Model typed timeouts by combining
Promise.raceand checked status or error types. - Choose clearly between sequential (
awaitin loop) and concurrent (all/allSettled) based on failure management.
Overview
Launching independent calls back to back with multiple await doubles or triples the latency unnecessarily. Promise's static combinators perform operations in parallel, and TypeScript exactly preserves the type of each branch involved.
By passing a literal list [fetchUser(), fetchOrders()] to Promise.all, TypeScript infers a tuple of distinct types, not a mixed array!
Sections covered in this lesson
- 1
Promise.all: heterogeneous tuple inference - 2
Promise.allSettled: failsafe with native Narrowing - 3
Promise.raceandPromise.any - 4Guided practice
- 5Check for understanding
Unlock "Typed Concurrency: Promise.all, allSettled and race" and the full Course TypeScript curriculum
Take advantage of the tuple inference of Promise.all and manage partial outcomes with PromiseSettledResult<T>.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Course TypeScript plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.