concurrency-patterns by aj-geddes/useful-ai-prompts
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill concurrency-patterns使用适当的同步原语和并行执行模式来实现安全的并发代码。
最小工作示例:
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();
// ... (完整实现请参阅参考指南)
references/ 目录下的详细实现:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 指南 | 内容 |
|---|---|
| Promise Pool (TypeScript) | Promise 池 (TypeScript) |
| Mutex and Semaphore (TypeScript) | 互斥锁与信号量 (TypeScript) |
| Worker Pool (Node.js) | 工作线程池 (Node.js) |
| Python Threading Patterns | Python 线程模式 |
| Async Patterns (Python asyncio) | 异步模式 (Python asyncio) |
| Go-Style Channels (Simulation) | Go 风格通道 (模拟) |
每周安装数
119
代码仓库
GitHub 星标数
121
首次出现
2026年1月21日
安全审计
安装于
opencode100
gemini-cli98
codex96
claude-code93
cursor91
github-copilot82
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) |
Weekly Installs
119
Repository
GitHub Stars
121
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode100
gemini-cli98
codex96
claude-code93
cursor91
github-copilot82
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
157,400 周安装