Loading...
Loading...
Use when performing parallel operations, rate limiting, or signaling between fibers in Effect-TS.
npx skill4agent add mrevanzak/effect-ts-skills effect-ts-concurrencyEffect.allEffect.forEachPromise.all| Pattern | Implementation | Result |
|---|---|---|
| BAD | | Unbounded - crashes on large inputs |
| GOOD | | Bounded - safe and predictable |
| Tool | Purpose | Key Method |
|---|---|---|
| Fiber | Background execution | |
| Semaphore | Bounded concurrency / Rate limiting | |
| Deferred | One-shot signaling / Promises | |
| concurrency | Option for | `{ concurrency: number |
import { Effect } from 'effect';
// Process 1000 items, max 10 concurrent
const results = yield* Effect.all(
items.map(processItem),
{ concurrency: 10 }
);import { Effect } from 'effect';
const program = Effect.gen(function* () {
const semaphore = yield* Effect.makeSemaphore(5); // Max 5 concurrent
yield* Effect.all(
requests.map((req) =>
semaphore.withPermits(1)(handleRequest(req))
),
{ concurrency: 'unbounded' } // Semaphore controls actual concurrency
);
});import { Deferred, Effect, Fiber } from 'effect';
const program = Effect.gen(function* () {
const signal = yield* Deferred.make<void>();
const worker = yield* Effect.fork(
Effect.gen(function* () {
yield* Deferred.await(signal); // Wait for signal
yield* doWork();
})
);
yield* setup();
yield* Deferred.succeed(signal, undefined); // Trigger worker
yield* Fiber.join(worker);
});{ concurrency: n }Effect.allEffect.scopedEffect.all{ concurrency: n }Promise.allsetTimeoutEffect.makeRateLimiterSemaphore| Excuse | Reality |
|---|---|
| "It's only 100 items" | 100 items today, 10,000 tomorrow. Bound it now. |
| "The API is fast" | Network latency and server load are unpredictable. |
| "I'll add concurrency later" | Unbounded parallelism is a ticking time bomb. |