mcpField
C
concurrency-patterns

concurrency-patterns

github.com/aj-geddes開発373472 回インストール34 週間前に更新
リポジトリ

concurrency-patterns について

同期プリミティブと並列実行パターンを用いて、安全な並行コードを実装するためのスキルです。TypeScript、Node.js、Python、Go風の例を含むリファレンスを提供します。

主な機能

  1. 01TypeScriptのPromiseプールパターン
  2. 02ミューテックスとセマフォのガイド
  3. 03Node.jsのワーカープールパターン
  4. 04Pythonのスレッドとasyncioのパターン
  5. 05Go風チャネルのシミュレーション
  6. 06並行処理の安全対策

活用シーン

  1. 01並列タスクの実行数の制限
  2. 02並行ワーカーの調整
  3. 03共有状態での競合状態の防止
  4. 04Pythonでの非同期パターンの適用

インストール

コマンドをコピーしてターミナルで実行します。

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

インストール後、Claude Code で/concurrency-patternsを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

references/
async-patterns-python-asyncio.md
go-style-channels-simulation.md
mutex-and-semaphore-typescript.md
promise-pool-typescript.md
python-threading-patterns.md
worker-pool-nodejs.md
scripts/
validate-api.sh
templates/
api-scaffold.yaml

詳細

並行処理パターン

目次

概要

適切な同期プリミティブとパターンを使用して、安全な並行コードを実装し、並列実行を実現します。

使用する場面

  • マルチスレッドアプリケーション
  • 並列データ処理
  • 競合状態の防止
  • リソースプーリング
  • タスクの調整
  • 高性能システム
  • 非同期処理
  • ワーカープール

クイックスタート

最小限の動作例:

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)

リファレンスガイド

詳細な実装は references/ ディレクトリにあります:

ガイド内容
Promise Pool (TypeScript)Promise Pool (TypeScript)
Mutex and Semaphore (TypeScript)Mutex and Semaphore (TypeScript)
Worker Pool (Node.js)Worker Pool (Node.js)
Python Threading PatternsPython Threading Patterns
Async Patterns (Python asyncio)Async Patterns (Python asyncio)
Go-Style Channels (Simulation)Go-Style Channels (Simulation)

ベストプラクティス

✅ 推奨事項
  • 適切な同期プリミティブを使用する
  • リソースの枯渇を避けるため、並行処理数を制限する
  • 並行処理で発生するエラーに対処する
  • 可能な場合は不変データを使用する
  • 並行コードを十分にテストする
  • 並行処理のパフォーマンスをプロファイリングする
  • スレッドセーフ性の保証を文書化する
❌ 禁止事項
  • 同期せずに変更可能な状態を共有する
  • 調整にスリープやポーリングを使用する
  • 無制限にスレッドやワーカーを作成する
  • 競合状態を無視する
  • 非同期コードでイベントループをブロックする
  • リソースのクリーンアップを忘れる

コメント