--- title: Promise.all() for Independent Operations impact: CRITICAL impactDescription: 2-10× improvement tags: async, parallelization, promises, waterfalls --- ## Promise.all() 用于独立操作 当异步操作之间没有依赖关系时,使用 `Promise.all()` 并发执行它们。 **错误(顺序执行,3 次往返):** ```typescript const user = await fetchUser() const posts = await fetchPosts() const comments = await fetchComments() ``` **正确(并行执行,1 次往返):** ```typescript const [user, posts, comments] = await Promise.all([ fetchUser(), fetchPosts(), fetchComments() ]) ```