concurrency-pattern-3-coordinate-multiple-fibers-with-latch

concurrency-pattern-3-coordinate-multiple-fibers-with-latch is a cursor rule for Cursor from PaulJPhilp/EffectPatterns. It costs 1,106 tokens per session, scanned A, original, MIT.

A TypeScript Effect rule for coordinating several concurrent workers with a latch, a shared signal that tells waiting tasks when work is complete.

In plain words
What is it for?
Use it for fan-out and fan-in work, barrier synchronization, and waiting for multiple concurrent tasks to complete.
Why use it?
It gives parallel tasks a clear completion point, avoiding ad-hoc tracking when many operations must finish before the next step.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it for fan-out and fan-in work, barrier synchronization, and waiting for multiple concurrent tasks to complete.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/pauljphilp/effectpatterns/concurrency-pattern-3-coordinate-multiple-fibers-with-latch
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/PaulJPhilp/EffectPatterns

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for concurrency-pattern-3-coordinate-multiple-fibers-with-latch

README.md
[![agentmods](https://agentmods.dev/badge/rules/pauljphilp/effectpatterns/concurrency-pattern-3-coordinate-multiple-fibers-with-latch/github.svg)](https://agentmods.dev/rules/pauljphilp/effectpatterns/concurrency-pattern-3-coordinate-multiple-fibers-with-latch)
Your own site
<a href="https://agentmods.dev/rules/pauljphilp/effectpatterns/concurrency-pattern-3-coordinate-multiple-fibers-with-latch"><img src="https://agentmods.dev/badge/rules/pauljphilp/effectpatterns/concurrency-pattern-3-coordinate-multiple-fibers-with-latch/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for concurrency-pattern-3-coordinate-multiple-fibers-with-latch

Your own site · 80×15
<a href="https://agentmods.dev/rules/pauljphilp/effectpatterns/concurrency-pattern-3-coordinate-multiple-fibers-with-latch"><img src="https://agentmods.dev/badge/rules/pauljphilp/effectpatterns/concurrency-pattern-3-coordinate-multiple-fibers-with-latch.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 1,106 This file is loaded in full into every session.
When invoked 1,106 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.01106 $0.01106
Opus 5 $0.00553 $0.00553
Sonnet 5 $0.00221 $0.00221
Haiku 4.5 $0.00111 $0.00111

Measured 9d ago against content hash e20f95dc1a03, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

concurrency-pattern-3-coordinate-multiple-fibers-with-latch scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

content/published/rules/cursor/concurrency-pattern-3-coordinate-multiple-fibers-with-latch.mdc · 145 lines

How it starts

The opening of the file, as written. The whole thing — 145 lines — stays where its author put it; the contents beside it link to each section on GitHub.

description: Use Latch to coordinate multiple fibers awaiting a common completion signal, enabling fan-out/fan-in and barrier synchronization patterns. globs: "**/*.ts" alwaysApply: true

Concurrency Pattern 3: Coordinate Multiple Fibers with Latch

Rule: Use Latch to coordinate multiple fibers awaiting a common completion signal, enabling fan-out/fan-in and barrier synchronization patterns.

Example

This example demonstrates a fan-out/fan-in pattern: spawn 5 worker fibers that process tasks in parallel, and coordinate to know when all are complete.

import { Effect, Latch, Fiber, Ref } from "effect";

interface WorkResult {
  readonly workerId: number;
  readonly taskId: number;
  readonly result: string;
  readonly duration: number;
}

// Simulate a long-running task
const processTask = (
  workerId: number,
  taskId: number
): Effect.Effect<WorkResult> =>
  Effect.gen(function* () {
    const startTime = Date.now();
    const duration = 100 + Math.random() * 400; // 100-500ms

    yield* Effect.log(
      `[Worker ${workerId}] Starting task ${taskId} (duration: ${Math.round(duration)}ms)`
    );

    yield* Effect.sleep(`${Math.round(duration)} millis`);

    const elapsed = Date.now() - startTime;

    yield* Effect.log(
      `[Worker ${workerId}] ✓ Completed task ${taskId} in ${elapsed}ms`
    );

    return {
      workerId,
      taskId,
      result: `Result from worker ${workerId} on task ${taskId}`,
      duration: elapsed,
    };
  });

// Fan-out/Fan-in with Latch
const fanOutFanIn = Effect.gen(function* () {
  const numWorkers = 5;
  const tasksPerWorker = 3;

  // Create latch: will countdown from (numWorkers) when all workers complete
  const workersCompleteLatch = yield* Latch.make(numWorkers);

  // Track results from all workers
  const results = yield* Ref.make<WorkResult[]>([]);

  // Worker fiber that processes tasks sequentially
  const createWorker = (workerId: number) =>
    Effect.gen(function* () {
      try {
        yield* Effect.log(`[Worker ${workerId}] ▶ Starting`);

        // Process multiple tasks
        for (let i = 1; i <= tasksPerWorker; i++) {
          const result = yield* processTask(workerId, i);
          yield* Ref.update(results, (rs) => [...rs, result]);
        }

        yield* Effect.log(`[Worker ${workerId}] ✓ All tasks completed`);
      } finally {
        // Signal completion to latch
        yield* Latch.countDown(workersCompleteLatch);
        yield* Effect.log(`[Worker ${workerId}] Signaled latch`);
      }
    });

  // Spawn all workers as background fibers
  console.log(`\n[COORDINATOR] Spawning ${numWorkers} workers...\n`);

  const workerFibers = yield* Effect.all(
    Array.from({ length: numWorkers }, (_, i) =>
      createWorker(i + 1).pipe(Effect.fork)
    )
  );

  // Wait for all workers to complete
  console.log(`\n[COORDINATOR] Waiting for all workers to finish...\n`);

  yield* Latch.await(workersCompleteLatch);

  console.log(`\n[COORDINATOR] All workers completed!\n`);

  // Join all fibers to ensure cleanup
  yield* Effect.all(workerFibers.map((fiber) => Fiber.join(fiber)));

  // Aggregate results
  const allResults = yield* Ref.get(results);

  console.log(`[SUMMARY]`);
  console.log(`  Total workers: ${numWorkers}`);
  console.log(`  Tasks per worker: ${tasksPerWorker}`);
  console.log(`  Total tasks: ${allResults.length}`);
  console.log(
    `  Avg task duration: ${Math.round(
      allResults.reduce((sum, r) => sum + r.duration, 0) / allResults.length
    )}ms`
  );
});

Effect.runPromise(fanOutFanIn);

Read the full file on GitHub · 145 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 145 lines · 1,106 tokens per session scan A e20f95dc1a03

Subscribe to this mod's changes

concurrency-pattern-3-coordinate-multiple-fibers-with-latch is a cursor rule published in the GitHub repository PaulJPhilp/EffectPatterns (796 stars, last pushed 2mo ago), licensed MIT. It adds 1,106 tokens to every session, about $0.0055 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.