Implement thread-safe code, mutexes, semaphores, async/await patterns, and concurrent data structures. Use when handling parallel operations, race conditions, or building high-performance concurrent systems.
Implement safe concurrent code using proper synchronization primitives and patterns for parallel execution.
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)
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) |
Copy a source-pinned command for your client. You run it yourself.
Destination: .claude/skills/concurrency-patterns · pinned to the source commit
git clone https://github.com/aj-geddes/useful-ai-prompts.git
cd useful-ai-prompts
git checkout 3f5182cfd739fc113f4af5244a1cf342ad7f7911
mkdir -p ".claude/skills/concurrency-patterns"
cp -r "skills/concurrency-patterns" ".claude/skills/concurrency-patterns"Review the source before running. This copies files into your project; it is not a one-click install and does not verify runtime safety.
Scanner static-checks@0.1.0 · commit 3f5182cfd739. Static checks cannot prove runtime safety – review the source and the exact diff before installing. How checks work.
No static rules matched. This is not a safety guarantee.