Skip to content

의존성 기반 병렬 처리 ​

Overview ​

For operations with partial dependencies, use better-all to maximize parallelism. It automatically starts each task at the earliest possible moment.

Impact ​

  • Priority: CRITICAL
  • Performance: 2-10× improvement

Problem ​

When some tasks have dependencies, Promise.all() alone makes optimization difficult.

Incorrect (profile waits for config unnecessarily) ​

typescript
const [user, config] = await Promise.all([fetchUser(), fetchConfig()])
const profile = await fetchProfile(user.id)

profile only needs user but waits for config too.

Correct (config and profile run in parallel) ​

typescript
import { all } from "better-all"

const { user, config, profile } = await all({
  async user() {
    return fetchUser()
  },
  async config() {
    return fetchConfig()
  },
  async profile() {
    return fetchProfile((await this.$.user).id)
  },
})

How It Works ​

better-all analyzes dependencies of each task:

  1. user and config run in parallel immediately
  2. profile starts as soon as user completes
  3. config and profile execute simultaneously

Execution Timeline ​

Normal approach:
user     ████████
config   ████████
         ↓ wait for both
profile         ████████

better-all:
user     ████████
config   ████████████████
profile         ████████
         ↑ starts after user only

Key Points ​

  • Auto-optimizes complex dependency chains
  • Reference other task Promises with this.$
  • Auto-detects all possible parallelism
  • No manual Promise management needed

Use Cases ​

  • Multiple API calls with partial dependencies
  • Fetching multiple data after authentication
  • Complex data pipelines

Reference ​

Library: better-all


Tags: async, parallelization, dependencies, better-all