Concurrency patterns (all/settled/race) types
Model concurrency with Promise.all / allSettled / race, understand their result types, and build safe helpers.
Intro
Goal: Run tasks concurrently with Promise.all, handle mixed outcomes via allSettled, and use race for timeouts/fallbacks. Learn the types each returns.
all: tuple types
Promise.all with a tuple preserves element types and order; each element is awaited to its inner type.
async function one(): Promise<number> { return 1 }
async function two(): Promise<string> { return "two" }
async function runAll() {
const [a, b] = await Promise.all([one(), two()]);
// a: number, b: string
console.log(a + 1, b.toUpperCase());
}
runAll();All lessons in this course
- Promise , async/await typing
- Error typing (unknown), narrowing in catch
- Concurrency patterns (all/settled/race) types