Back to Eliminating Waterfalls

Dependency-Based Parallelization

asyncparallelizationdependenciesbetter-all
28.0k🕒 2026-06-10Source ↗

Install this skill

npx skills add vercel-labs/agent-skills

Works across Claude Code, Cursor, Codex, Copilot & Antigravity

Dependency-Based Parallelization optimizes task execution flows that contain mixed sequential and independent operations. Standard JavaScript primitives like Promise.all force developers to choose between flat parallelization or nested serial waterfalls, often creating unnecessary idle time. This skill uses the better-all pattern to define task graphs where child operations resolve as soon as their specific upstream dependencies finish, rather than waiting for every sibling task to complete. By mapping dependencies within an execution object, the agent initiates I/O-bound requests at the earliest moment technically feasible. This results in shorter total execution duration for complex data fetching logic where some attributes depend on early identifiers while others remain isolated from the primary chain. It effectively flattens complex request trees into a single, efficient concurrent operation while maintaining strict data integrity.

When to Use This Skill

  • Fetching user account settings and profile details simultaneously
  • Loading related blog post data after initial user ID resolution
  • Running independent API configuration tasks alongside dependent data requests
  • Aggregating dashboard widgets with varied dependency trees

How to Invoke This Skill

Example prompts that trigger this skill in Claude Code, Cursor, or Antigravity:

  • Refactor this waterfall into a parallel dependency graph
  • How can I run these promises concurrently if one depends on the other?
  • Optimize this slow data fetching flow to use better-all
  • Reduce execution time by parallelizing these dependent API calls
  • Fix this sequential bottleneck using dependency-based parallelization

What this skill does

  • Maps task dependencies to maximize concurrency
  • Triggers dependent tasks immediately upon input resolution
  • Eliminates waterfall delays in nested data fetching
  • Provides a unified interface for mixed parallel-serial logic
  • Automatically manages promise resolution order based on defined keys

When not to use it

  • When tasks have no dependencies and simple Promise.all suffices
  • When task operations perform side effects that require strict global ordering
  • When memory constraints prevent simultaneous execution of all tasks

Example workflow

  1. Identify current sequential code blocks causing latency
  2. Map out which functions require previous function outputs
  3. Initialize the better-all structure with independent task definitions
  4. Inject dependencies using the context-aware reference pattern
  5. Execute and verify that total runtime matches the longest single dependency chain

Prerequisites

  • Node.js environment
  • better-all dependency installed
  • Async/await understanding

Pitfalls & limitations

  • !Over-engineering simple promise chains
  • !Misdefining dependency keys leading to runtime errors
  • !Ignoring error propagation differences compared to native Promise.all

FAQ

How does this differ from Promise.all?
Promise.all waits for all tasks to finish before returning. Dependency-based parallelization allows specific branches of the operation to start as soon as their required inputs exist.
Can I use this for non-async functions?
The pattern is optimized for asynchronous operations. Synchronous tasks should be handled outside the library to prevent blocking the event loop.
What happens if a dependency fails?
If an upstream task fails, the dependent tasks will throw or return an error state, mirroring standard promise rejection behavior.
Is this faster than standard serial execution?
Yes, it significantly reduces latency by ensuring that no task sits idle waiting for an unrelated task to finish.

How it compares

Unlike manual Promise.all chains which create rigid waterfalls, this approach builds an execution graph that calculates the shortest possible time to completion for interdependent tasks.

Source & trust

28k stars🕒 Updated 2026-06-10
📄 Full skill instructions — original source: vercel-labs/agent-skills
## Dependency-Based Parallelization

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

**Incorrect (profile waits for config unnecessarily):**

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


**Correct (config and profile run in parallel):**

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)
}
})


Reference: [https://github.com/shuding/better-all](https://github.com/shuding/better-all)

How to Use This Skill Unit

Option A: Project-Specific (Recommended)

  1. Click "Download" above
  2. In your project, create the directory: .agent/skills/async-dependencies/
  3. Save the file as SKILL.md
  4. The agent will automatically discover the skill based on its description.

Option B: Global Installation (All Agents)

Save the file to these locations to make it available across all projects:

  • Claude Code: ~/.claude/skills/vercel-labs/agent-skills/async-dependencies/SKILL.md
  • Cursor: ~/.cursor/skills/vercel-labs/agent-skills/async-dependencies/SKILL.md
  • Antigravity: ~/.gemini/antigravity/skills/vercel-labs/agent-skills/async-dependencies/SKILL.md

🚀 Install with CLI:
npx skills add vercel-labs/agent-skills

Read the Master Guide: Mastering Agent Skills

Recommended Rules

View more rules

Recommended Workflows

View more workflows

Recommended MCP Servers

View more MCP servers

Take It Further

Maximize your productivity with these powerful resources

📋

Define Your Standards

Set up coding standards to ensure this workflow produces consistent, high-quality results.

Browse Rules Library
📖

Master Workflows

Learn how to create custom workflows, use Turbo Mode, and build your automation library.

Complete Guide

How to use this Skill in Claude Code & Cursor

For Claude Code (CLI)

To use this skill in Claude Code, copy the rule content into your project's custom instructions or follow our Add-Skill CLI guide. This ensures Claude follows your standards during every code generation.

For Cursor & Windsurf

For Cursor or Windsurf, individual skills are best used in the "Rules for AI" section. This specific unit helps the agent avoid eliminating waterfalls issues, leading to cleaner, more efficient code.

Why the skill format matters: the standardized Agent Skills format lets your AI agent load detailed instructions only when they are relevant, keeping your prompt clean while improving results.

Source & attribution

This skill is categorized under Eliminating Waterfalls and is published by Vercel Engineering, maintained in vercel-labs/agent-skills.

← Browse All Agent Skills
Sponsored AI assistant. Recommendations may be paid.