How dependency optimization works in better-all
mainThe better-all library automatically optimizes task execution by analyzing dependencies declared via this.$.
Unlike Promise.all, which requires manual orchestration to parallelize tasks that depend on others, better-all kicks off all tasks immediately. When a task hits await this.$.dependency, it pauses only for that specific dependency. This ensures maximal parallelization: independent tasks run in parallel, while dependent tasks wait only as long as necessary.
Example of automatic optimization:
import { all } from 'better-all'
const { a, b, c } = await all({
async a() { return getA() }, // 1s
async b() { return getB() }, // 10s
async c() { return getC(await this.$.a) } // 10s (waits for a)
})
// Total: 11 seconds - optimal parallelization!import { all } from 'better-all'
const { a, b, c } = await all({
async a() { return getA() }, // 1s
async b() { return getB() }, // 10s
async c() { return getC(await this.$.a) } // 10s (waits for a)
})