Claude Skills
CollectionsCompareWorkflowsNominate
Sign inSign up
© 2026 Curated Agent Skills·Learn more about Agent Skills
Back to repository

node-async-patterns

verified

Node.js async/await patterns

View on GitHub

Marketplace

alphaagent-team

the-answerai/alphaagent-team

Plugin

aai-stack-node

stack

Repository

the-answerai/alphaagent-team

plugins/aai-stack-node/skills/node-async-patterns/SKILL.md

Last Verified

February 1, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/the-answerai/alphaagent-team/blob/main/plugins/aai-stack-node/skills/node-async-patterns/SKILL.md -a claude-code --skill node-async-patterns

Installation paths:

Claude
.claude/skills/node-async-patterns/
Powered by add-skill CLI

Instructions

# Node.js Async Patterns Skill

Patterns for asynchronous programming in Node.js.

## Promise Patterns

### Creating Promises

```typescript
// Basic promise
function delay(ms: number): Promise<void> {
  return new Promise(resolve => setTimeout(resolve, ms))
}

// Promise with value
function fetchData(): Promise<Data> {
  return new Promise((resolve, reject) => {
    // async operation
    if (success) {
      resolve(data)
    } else {
      reject(new Error('Failed'))
    }
  })
}

// Promisifying callbacks
import { promisify } from 'util'
import { readFile } from 'fs'

const readFileAsync = promisify(readFile)
const content = await readFileAsync('file.txt', 'utf8')
```

### Promise Combinators

```typescript
// All (parallel, all must succeed)
const [users, posts] = await Promise.all([
  fetchUsers(),
  fetchPosts(),
])

// All with error handling
const results = await Promise.allSettled([
  fetchUsers(),
  fetchPosts(),
  fetchComments(),
])

results.forEach((result, i) => {
  if (result.status === 'fulfilled') {
    console.log(`Result ${i}:`, result.value)
  } else {
    console.error(`Error ${i}:`, result.reason)
  }
})

// Race (first to complete)
const result = await Promise.race([
  fetchFromServer1(),
  fetchFromServer2(),
])

// Any (first to succeed)
const result = await Promise.any([
  fetchFromServer1(),
  fetchFromServer2(),
])
```

### Promise Utilities

```typescript
// Timeout wrapper
function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {
  const timeout = new Promise<never>((_, reject) =>
    setTimeout(() => reject(new Error('Timeout')), ms)
  )
  return Promise.race([promise, timeout])
}

// Retry wrapper
async function retry<T>(
  fn: () => Promise<T>,
  retries: number = 3,
  delay: number = 1000
): Promise<T> {
  for (let i = 0; i < retries; i++) {
    try {
      return await fn()
    } catch (err) {
      if (i === retries - 1) throw err
      await new Promise(r => setTimeout(r, delay * Math.pow(2, i)))
    }
  }
  throw n

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
6876 chars