|
1 | 1 | # effect |
2 | 2 |
|
| 3 | +## 3.19.4 |
| 4 | + |
| 5 | +### Patch Changes |
| 6 | + |
| 7 | +- [#5752](https://github.com/Effect-TS/effect/pull/5752) [`f445b87`](https://github.com/Effect-TS/effect/commit/f445b87bab342188a5c223cfc76c697d65594d1d) Thanks @janglad! - Fix Types.DeepMutable mapping over functions |
| 8 | + |
| 9 | +- [#5757](https://github.com/Effect-TS/effect/pull/5757) [`d2b68ac`](https://github.com/Effect-TS/effect/commit/d2b68ac9e1ac1d58d7387715843c448195f14675) Thanks @tim-smart! - add experimental PartitionedSemaphore module |
| 10 | + |
| 11 | + A `PartitionedSemaphore` is a concurrency primitive that can be used to |
| 12 | + control concurrent access to a resource across multiple partitions identified |
| 13 | + by keys. |
| 14 | + |
| 15 | + The total number of permits is shared across all partitions, with waiting |
| 16 | + permits equally distributed among partitions using a round-robin strategy. |
| 17 | + |
| 18 | + This is useful when you want to limit the total number of concurrent accesses |
| 19 | + to a resource, while still allowing for fair distribution of access across |
| 20 | + different partitions. |
| 21 | + |
| 22 | + ```ts |
| 23 | + import { Effect, PartitionedSemaphore } from "effect" |
| 24 | + |
| 25 | + Effect.gen(function* () { |
| 26 | + const semaphore = yield* PartitionedSemaphore.make<string>({ permits: 5 }) |
| 27 | + |
| 28 | + // Take the first 5 permits with key "A", then the following permits will be |
| 29 | + // equally distributed between all the keys using a round-robin strategy |
| 30 | + yield* Effect.log("A").pipe( |
| 31 | + Effect.delay(1000), |
| 32 | + semaphore.withPermits("A", 1), |
| 33 | + Effect.replicateEffect(15, { concurrency: "unbounded" }), |
| 34 | + Effect.fork |
| 35 | + ) |
| 36 | + yield* Effect.log("B").pipe( |
| 37 | + Effect.delay(1000), |
| 38 | + semaphore.withPermits("B", 1), |
| 39 | + Effect.replicateEffect(10, { concurrency: "unbounded" }), |
| 40 | + Effect.fork |
| 41 | + ) |
| 42 | + yield* Effect.log("C").pipe( |
| 43 | + Effect.delay(1000), |
| 44 | + semaphore.withPermits("C", 1), |
| 45 | + Effect.replicateEffect(10, { concurrency: "unbounded" }), |
| 46 | + Effect.fork |
| 47 | + ) |
| 48 | + |
| 49 | + return yield* Effect.never |
| 50 | + }).pipe(Effect.runFork) |
| 51 | + ``` |
| 52 | + |
3 | 53 | ## 3.19.3 |
4 | 54 |
|
5 | 55 | ### Patch Changes |
|
0 commit comments