EntityResource.ts
EntityResource.ts overview
Section titled “EntityResource.ts overview”Keeps resources available across cluster entity restarts.
EntityResource is useful for long-lived resources tied to an entity
address, such as external processes, network clients, Kubernetes Pods, or
other handles that should survive routine shard movement. This module
includes the resource wrapper, a close scope that survives normal entity
restarts, a generic resource constructor, and a Kubernetes Pod resource
helper built on K8sHttpClient.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”Kubernetes
Section titled “Kubernetes”makeK8sPod
Section titled “makeK8sPod”Creates an EntityResource backed by a Kubernetes Pod.
Details
The pod is created and waited on through K8sHttpClient, and is kept alive
until the resource is closed or its idle time to live expires.
Signature
declare const makeK8sPod: ( spec: v1.Pod, options?: { readonly idleTimeToLive?: Duration.Input | undefined } | undefined) => Effect.Effect< EntityResource<K8sHttpClient.PodStatus>, never, Scope.Scope | Sharding | Entity.CurrentAddress | K8sHttpClient.K8sHttpClient>Since v4.0.0
constructors
Section titled “constructors”Creates an EntityResource that can be acquired inside a cluster entity.
When to use
Use when a cluster entity should lazily share an acquired resource across messages and release it only on idle timeout or explicit close.
Details
The resource will only be fully released when the idle time to live is
reached, or when the close effect is called.
Gotchas
By default, the idleTimeToLive is infinite, meaning the resource will only
be released when close is called.
Signature
declare const make: <A, E, R>(options: { readonly acquire: Effect.Effect<A, E, R> readonly idleTimeToLive?: Duration.Input | undefined readonly acquireEagerly?: boolean | undefined}) => Effect.Effect<EntityResource<A, E>, E, Scope.Scope | Exclude<R, CloseScope> | Sharding | Entity.CurrentAddress>Since v4.0.0
models
Section titled “models”EntityResource (interface)
Section titled “EntityResource (interface)”A resource acquired inside a cluster entity and kept alive across restarts.
Details
get acquires or reuses the resource in the caller’s scope, while close
invalidates it so its close scope can be released.
Signature
export interface EntityResource<out A, out E = never> { readonly [TypeId]: TypeId readonly get: Effect.Effect<A, E, Scope.Scope> readonly close: Effect.Effect<void>}Since v4.0.0
resource management
Section titled “resource management”CloseScope (class)
Section titled “CloseScope (class)”Context service for a Scope that is only closed when the resource is explicitly closed.
When to use
Use when a cluster entity resource needs a scope that survives restarts and closes only through the resource lifecycle.
Gotchas
It is not closed during restarts, due to shard movement or node shutdowns.
Signature
declare class CloseScopeSince v4.0.0
type IDs
Section titled “type IDs”TypeId
Section titled “TypeId”Type identifier used to brand EntityResource values.
Signature
declare const TypeId: "~effect/cluster/EntityResource"Since v4.0.0
TypeId (type alias)
Section titled “TypeId (type alias)”Literal type of the EntityResource type identifier.
Signature
type TypeId = "~effect/cluster/EntityResource"Since v4.0.0