依赖链
fetchOrders 需要 profile.userId,所以第一段必须先 await fetchProfile 再 await fetchOrders(profile.userId)——顺序由数据流决定,chain 行打印拼接结果。
无关调用并行
fetchNotice 不依赖任何东西,第二段把整条链(fetchProfile().then(p => fetchOrders(p.userId)))与 fetchNotice 放进同一个 Promise.all。两者立即同时开始,链内部依旧按序,notice 与链并行。
点名反模式
把 notice 串行地排在链前或链后,都会把它的完整延迟叠加到总时长上;示例的并行块就是结构性修复。
链内步骤能并行吗?
不能,每一步消费上一步的返回值,只能顺序 await。
Promise.all 的一个失败会怎样?
整体立刻 reject,其余 promise 的结果被丢弃;需要全部落定时用 allSettled。
链内步骤为什么不能并行?
每一步都要消费上一步的返回值(fetchOrders 需要 profile.userId),await 只能顺序执行。
无关调用应该放在哪?
放进与链同一个 Promise.all,让它与链并行,而不是串行排在依赖步骤前后。