|
1 | 1 | # @effect/cluster |
2 | 2 |
|
| 3 | +## 0.53.2 |
| 4 | + |
| 5 | +### Patch Changes |
| 6 | + |
| 7 | +- [#5778](https://github.com/Effect-TS/effect/pull/5778) [`af7916a`](https://github.com/Effect-TS/effect/commit/af7916a3f00acdfc8ce451eabd3f5fb02914d0bb) Thanks @tim-smart! - fix postgres unprocessed message ordering |
| 8 | + |
| 9 | +- [#5778](https://github.com/Effect-TS/effect/pull/5778) [`af7916a`](https://github.com/Effect-TS/effect/commit/af7916a3f00acdfc8ce451eabd3f5fb02914d0bb) Thanks @tim-smart! - add @effect/cluster EntityResource module |
| 10 | + |
| 11 | + A `EntityResource` is a resource that can be acquired inside a cluster |
| 12 | + entity, which will keep the entity alive even across restarts. |
| 13 | + |
| 14 | + The resource will only be fully released when the idle time to live is |
| 15 | + reached, or when the `close` effect is called. |
| 16 | + |
| 17 | + By default, the `idleTimeToLive` is infinite, meaning the resource will only |
| 18 | + be released when `close` is called. |
| 19 | + |
| 20 | + ```ts |
| 21 | + import { Entity, EntityResource } from "@effect/cluster" |
| 22 | + import { Rpc } from "@effect/rpc" |
| 23 | + import { Effect } from "effect" |
| 24 | + |
| 25 | + const EntityA = Entity.make("EntityA", [Rpc.make("method")]) |
| 26 | + |
| 27 | + export const EntityALayer = EntityA.toLayer( |
| 28 | + Effect.gen(function* () { |
| 29 | + // When the entity receives a message, it will first acquire the resource |
| 30 | + // |
| 31 | + // If the entity restarts, the resource will be re-acquired in the new |
| 32 | + // instance. |
| 33 | + // |
| 34 | + // It will only be released when the idle TTL is reached, or when the |
| 35 | + // `close` effect is called. |
| 36 | + const resource = yield* EntityResource.make({ |
| 37 | + acquire: Effect.acquireRelease( |
| 38 | + Effect.logInfo("Acquiring Entity resource"), |
| 39 | + () => Effect.logInfo("Releasing Entity resource") |
| 40 | + ), |
| 41 | + // If the resource is not used for 10 minutes, it will be released and the |
| 42 | + // entity will be allowed to shut down. |
| 43 | + idleTimeToLive: "10 minutes" |
| 44 | + }) |
| 45 | + |
| 46 | + return EntityA.of({ |
| 47 | + method: Effect.fnUntraced(function* () { |
| 48 | + yield* Effect.logInfo("EntityA.method called") |
| 49 | + // To access the resource, use `resource.get` inside an Effect.scoped |
| 50 | + yield* resource.get |
| 51 | + }, Effect.scoped) |
| 52 | + }) |
| 53 | + }), |
| 54 | + { |
| 55 | + // After the resource is released, if the entity is not used for 1 minute, |
| 56 | + // the entity will be shut down. |
| 57 | + maxIdleTime: "1 minute" |
| 58 | + } |
| 59 | + ) |
| 60 | + ``` |
| 61 | + |
| 62 | +- Updated dependencies [[`af7916a`](https://github.com/Effect-TS/effect/commit/af7916a3f00acdfc8ce451eabd3f5fb02914d0bb)]: |
| 63 | + |
| 64 | + |
3 | 65 | ## 0.53.1 |
4 | 66 |
|
5 | 67 | ### Patch Changes |
|
0 commit comments