concurrency-patterns

aj-geddes/useful-ai-prompts · updated Apr 8, 2026

$npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill concurrency-patterns
0 commentsdiscussion
summary

Implement safe concurrent code using proper synchronization primitives and patterns for parallel execution.

skill.md

Concurrency Patterns

Table of Contents

Overview

Implement safe concurrent code using proper synchronization primitives and patterns for parallel execution.

When to Use

  • Multi-threaded applications
  • Parallel data processing
  • Race condition prevention
  • Resource pooling
  • Task coordination
  • High-performance systems
  • Async operations
  • Worker pools

Quick Start

Minimal working example:

class PromisePool {
  private queue: Array<() => Promise<any>> = [];
  private active = 0;

  constructor(private concurrency: number) {}

  async add<T>(fn: () => Promise<T>): Promise<T> {
    while (this.active >= this.concurrency) {
      await this.waitForSlot();
    }

    this.active++;

    try {
      return await fn();
    } finally {
      this.active--;
    }
  }

  private async waitForSlot(): Promise<void> {
    return new Promise((resolve) => {
      const checkSlot = () => {
        if (this.active < this.concurrency) {
          resolve();
// ... (see reference guides for full implementation)

Reference Guides

Detailed implementations in the references/ directory:

Guide Contents
Promise Pool (TypeScript) Promise Pool (TypeScript)
Mutex and Semaphore (TypeScript) Mutex and Semaphore (TypeScript)
Worker Pool (Node.js) Worker Pool (Node.js)
Python Threading Patterns Python Threading Patterns
Async Patterns (Python asyncio) Async Patterns (Python asyncio)
Go-Style Channels (Simulation) Go-Style Channels (Simulation)

Best Practices

✅ DO

  • Use proper synchronization primitives
  • Limit concurrency to avoid resource exhaustion
  • Handle errors in concurrent operations
  • Use immutable data when possible
  • Test concurrent code thoroughly
  • Profile concurrent performance
  • Document thread-safety guarantees

❌ DON'T

  • Share mutable state without synchronization
  • Use sleep/polling for coordination
  • Create unlimited threads/workers
  • Ignore race conditions
  • Block event loops in async code
  • Forget to clean up resources

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.838 reviews
  • Yuki Robinson· Dec 24, 2024

    Useful defaults in concurrency-patterns — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Shikha Mishra· Dec 20, 2024

    concurrency-patterns is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Ren Nasser· Dec 8, 2024

    concurrency-patterns reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Diego Desai· Nov 15, 2024

    I recommend concurrency-patterns for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Rahul Santra· Nov 11, 2024

    concurrency-patterns fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Emma Gonzalez· Oct 6, 2024

    Keeps context tight: concurrency-patterns is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Pratham Ware· Oct 2, 2024

    concurrency-patterns has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Diego Dixit· Sep 13, 2024

    concurrency-patterns fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Oshnikdeep· Sep 9, 2024

    Useful defaults in concurrency-patterns — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Evelyn Sethi· Sep 1, 2024

    concurrency-patterns has been reliable in day-to-day use. Documentation quality is above average for community skills.

showing 1-10 of 38

1 / 4