async-concurrency-patterns

Manages concurrent async operations with execution limits, cancellation propagation, and backpressure in TypeScript. Use when running parallel tasks, coordinating multiple agents, or handling streaming responses with rate limits.

16 stars

Best use case

async-concurrency-patterns is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Manages concurrent async operations with execution limits, cancellation propagation, and backpressure in TypeScript. Use when running parallel tasks, coordinating multiple agents, or handling streaming responses with rate limits.

Teams using async-concurrency-patterns should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/async-concurrency-patterns/SKILL.md --create-dirs "https://raw.githubusercontent.com/woojubb/robota/main/.agents/skills/async-concurrency-patterns/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/async-concurrency-patterns/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How async-concurrency-patterns Compares

Feature / Agentasync-concurrency-patternsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Manages concurrent async operations with execution limits, cancellation propagation, and backpressure in TypeScript. Use when running parallel tasks, coordinating multiple agents, or handling streaming responses with rate limits.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Async Concurrency Patterns

## Rule Anchor
- `AGENTS.md` > "Development Patterns"
- `AGENTS.md` > "Execution Safety"

## Use This Skill When
- Running multiple async operations in parallel (tool calls, agent executions).
- Needing to limit concurrent API calls to respect rate limits.
- Implementing user-initiated cancellation across an execution chain.
- Handling streaming responses where the consumer may be slower than the producer.

## Core Principles
1. **Fixed concurrency limit**: a sliding window of at most N concurrent promises.
2. **Cancellation propagation**: AbortController signals flow from outer to inner scopes.
3. **Backpressure**: producers slow down when consumers cannot keep up.
4. **Graceful degradation**: partial results are preserved when some operations fail.

## Patterns

### 1. Concurrency Limiter
```ts
async function mapWithLimit<T, R>(
  items: T[],
  limit: number,
  fn: (item: T, signal?: AbortSignal) => Promise<R>,
  signal?: AbortSignal
): Promise<R[]> {
  const results: R[] = [];
  const executing = new Set<Promise<void>>();

  for (const item of items) {
    if (signal?.aborted) throw new Error('Aborted');

    const p = fn(item, signal).then((r) => { results.push(r); });
    executing.add(p);
    p.finally(() => executing.delete(p));

    if (executing.size >= limit) await Promise.race(executing);
  }

  await Promise.all(executing);
  return results;
}
```

### 2. Cancellation with AbortController
```ts
const controller = new AbortController();

// Pass signal to all downstream operations
await executeAgent(input, { signal: controller.signal });

// Cancel from outside
controller.abort();

// Inside operations: check signal
if (signal?.aborted) throw new Error('Operation cancelled');
```

### 3. Settled Results (partial success)
```ts
const results = await Promise.allSettled(tasks.map((t) => execute(t)));
const succeeded = results.filter((r): r is PromiseFulfilledResult<T> => r.status === 'fulfilled');
const failed = results.filter((r): r is PromiseRejectedResult => r.status === 'rejected');
```

## Checklist
- [ ] Concurrent operations have an explicit limit (not unlimited Promise.all).
- [ ] AbortSignal is passed through the entire execution chain.
- [ ] Abort errors are caught and handled separately from real errors.
- [ ] Streaming producers respect consumer readiness (backpressure).
- [ ] Partial failures are handled (allSettled or explicit error collection).
- [ ] Rate limit retries use exponential backoff, not busy-wait.
- [ ] Resources (connections, handles) are cleaned up on cancellation.

## Anti-Patterns
- `Promise.all()` on unbounded arrays (memory/rate exhaustion).
- Ignoring AbortSignal in long-running operations.
- Catching abort errors and treating them as regular failures.
- Busy-waiting or fixed-delay retries for rate limits.
- Fire-and-forget promises without error handling.
- Using `setTimeout` for backpressure instead of flow control.

Related Skills

vercel-composition-patterns

16
from woojubb/robota

React composition patterns that scale. Use when refactoring components with boolean prop proliferation, building flexible component libraries, or designing reusable APIs. Triggers on tasks involving compound components, render props, context providers, or component architecture. Includes React 19 API changes.

ddd-tactical-patterns

16
from woojubb/robota

Applies Domain-Driven Design tactical patterns (Aggregate, Bounded Context, Value Object, Domain Event) to structure domain models with clear transactional boundaries. Use when designing domain objects, deciding ownership, or separating contexts.

architecture-patterns

16
from woojubb/robota

Applies Robota's architecture patterns — functional core/imperative shell, ports-and-adapters, and DI-based composition. Use when designing module boundaries, separating domain from infrastructure, or improving testability.

web-design-guidelines

16
from woojubb/robota

Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".

vitest-testing-strategy

16
from woojubb/robota

Defines a practical testing strategy for TypeScript and JavaScript using Vitest across unit, integration, and type-level tests. Use when adding features, refactoring, or preventing regressions with fast feedback loops.

version-management

16
from woojubb/robota

All packages must have the same version. Use changesets for coordinated version bumps. Never version packages independently.

vercel-react-native-skills

16
from woojubb/robota

React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.

vercel-react-best-practices

16
from woojubb/robota

React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.

user-request-gate

16
from woojubb/robota

Use immediately when the user requests any implementation, code change, feature addition, fix, or modification. Gates code writing behind a backlog draft document. Read-only exploration is always permitted.

type-boundary-and-ssot

16
from woojubb/robota

Applies Robota's preferred workflow for trust-boundary validation, strict typing, quality gates, and owner-based SSOT reuse. Use when adding or reviewing type contracts, boundary parsing, shared contract ownership, or running quality checks.

tdd-red-green-refactor

16
from woojubb/robota

Kent Beck's TDD workflow. Use when writing new code or modifying existing behavior. Enforces the Red-Green-Refactor cycle with small, verifiable steps.

task-tracking

16
from woojubb/robota

Track work using task files in .agents/tasks/. Use when starting, progressing, or completing a task to maintain a persistent record of work.