Back to Eliminating Waterfalls

Promise.all() for Independent Operations

asyncparallelizationpromiseswaterfalls
28.0k🕒 2026-06-10Source ↗

Install this skill

npx skills add vercel-labs/agent-skills

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

This pattern reduces latency in asynchronous JavaScript operations by executing independent tasks concurrently rather than waiting for each to finish before starting the next. By grouping promises into a single array passed to Promise.all(), the runtime initiates all network requests or file system operations simultaneously. This approach optimizes the total wait time to match the duration of the slowest individual task rather than the sum of all tasks. This technique is essential for performance-sensitive applications where multiple data sources must be fetched before rendering or processing can begin. It prevents the sequential blocking behavior inherent in repeated await statements, ensuring the event loop remains responsive and overall execution time is minimized without adding unnecessary complexity to the codebase.

When to Use This Skill

  • Fetching profile data, activity logs, and notification counts simultaneously on page load
  • Loading configuration files from different remote endpoints
  • Processing multiple separate database queries that do not rely on each other's output
  • Running independent validation checks across distinct data services

How to Invoke This Skill

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

  • Run these async tasks at the same time
  • Make my API calls parallel to save time
  • Stop waiting for each fetch to finish individually
  • Execute multiple promises concurrently
  • Optimize sequential await statements

What this skill does

  • Groups multiple independent asynchronous promises into a single execution unit
  • Aggregates result values into a single array matching input order
  • Minimizes total latency to the duration of the longest request
  • Provides a unified interface for handling concurrent I/O operations
  • Enables immediate rejection if any single promise within the array fails

When not to use it

  • When subsequent operations depend on the result of a previous promise
  • When you need to handle partial failures or continue even if one request errors

Example workflow

  1. Identify independent async functions that do not share state
  2. Map these functions into an array structure
  3. Pass the array into the Promise.all constructor
  4. Apply await to the entire Promise.all expression
  5. Destructure the returned array to access specific results

Prerequisites

  • Familiarity with JavaScript async/await syntax
  • Understanding of the event loop

Pitfalls & limitations

  • !Fails fast; one rejection causes the entire operation to reject immediately
  • !Does not inherently throttle the number of concurrent connections
  • !Requires careful error handling if partial success is desired

FAQ

What happens if one promise in the array fails?
Promise.all immediately rejects with the reason from the first promise that fails, ignoring results from remaining tasks.
Does the order of results change if one request is faster?
No, the resulting array maintains the exact order of the promises provided in the input array, regardless of completion timing.
Can I use this for tasks that depend on each other?
No, Promise.all is intended only for tasks that are independent. Use sequential await statements for dependent data.

How it compares

While manual sequencing blocks the thread unnecessarily for each task, Promise.all orchestrates parallel execution to collapse multiple round-trips into one.

Source & trust

28k stars🕒 Updated 2026-06-10
📄 Full skill instructions — original source: vercel-labs/agent-skills
## Promise.all() for Independent Operations

When async operations have no interdependencies, execute them concurrently using Promise.all().

**Incorrect (sequential execution, 3 round trips):**

const user = await fetchUser()
const posts = await fetchPosts()
const comments = await fetchComments()


**Correct (parallel execution, 1 round trip):**

const [user, posts, comments] = await Promise.all([
fetchUser(),
fetchPosts(),
fetchComments()
])

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-parallel/
  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-parallel/SKILL.md
  • Cursor: ~/.cursor/skills/vercel-labs/agent-skills/async-parallel/SKILL.md
  • Antigravity: ~/.gemini/antigravity/skills/vercel-labs/agent-skills/async-parallel/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.