Files
2026-07-13 21:36:17 +08:00

629 B
Raw Permalink Blame History

title, impact, impactDescription, tags
title impact impactDescription tags
Promise.all() for Independent Operations CRITICAL 2-10× improvement async, parallelization, promises, waterfalls

Promise.all() 用于独立操作

当异步操作之间没有依赖关系时,使用 Promise.all() 并发执行它们。

错误(顺序执行,3 次往返):

const user = await fetchUser()
const posts = await fetchPosts()
const comments = await fetchComments()

正确(并行执行,1 次往返):

const [user, posts, comments] = await Promise.all([
  fetchUser(),
  fetchPosts(),
  fetchComments()
])