xonecas.io
556
Bn

bees-nest / files

bees-nest / .opencode / skills / vercel-react-best-practices / rules / async-parallel.md

654 bytes
1---
2title: Promise.all() for Independent Operations
3impact: CRITICAL
4impactDescription: 2-10× improvement
5tags: async, parallelization, promises, waterfalls
6---
7
8## Promise.all() for Independent Operations
9
10When async operations have no interdependencies, execute them concurrently using `Promise.all()`.
11
12**Incorrect (sequential execution, 3 round trips):**
13
14```typescript
15const user = await fetchUser()
16const posts = await fetchPosts()
17const comments = await fetchComments()
18```
19
20**Correct (parallel execution, 1 round trip):**
21
22```typescript
23const [user, posts, comments] = await Promise.all([
24  fetchUser(),
25  fetchPosts(),
26  fetchComments()
27])
28```