Leases
Decides which process runs each view model.
Replicas that share an event store would otherwise all run the same view
models and race on their checkpoints. ViewModel.layer takes a lease on each
view model before running it: the process that holds the lease runs it, and the
others wait as standbys until it is given up.
Classes
Section titled “Classes”Leases
Section titled “Leases”Defined in: src/Leases.ts:21
Extends
Section titled “Extends”Shape<"effect-cqrs/Leases", {acquire(name):Effect<Lease,never,Scope>; },this>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Leases(
_):Leases
Defined in: node_modules/.pnpm/effect@4.0.6/node_modules/effect/dist/Context.d.ts:121
Parameters
Section titled “Parameters”never
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Context.Service<Leases, { /** * Competes for the lease called `name` until the scope closes, which gives it * up. The first attempt is made before this returns. */ acquire(name: string): Effect.Effect<Lease, never, Scope.Scope> }>()("effect-cqrs/Leases").constructor
Interfaces
Section titled “Interfaces”Defined in: src/Leases.ts:14
Properties
Section titled “Properties”changes
Section titled “changes”
readonlychanges:Stream<boolean>
Defined in: src/Leases.ts:18
Emits whether the lease is held, then every change.
readonlyheld:Effect<boolean>
Defined in: src/Leases.ts:16
Whether this process holds the lease now.
PostgresOptions
Section titled “PostgresOptions”Defined in: src/Leases.ts:39
Properties
Section titled “Properties”interval?
Section titled “interval?”
readonlyoptionalinterval?:Input
Defined in: src/Leases.ts:44
How often a standby tries to take a lease over, and the holder checks that its connection is alive. Defaults to 5 seconds.
prefix?
Section titled “prefix?”
readonlyoptionalprefix?:string
Defined in: src/Leases.ts:46
Prefixes the names, so that several applications can share a database. Defaults to effect-cqrs/.
Variables
Section titled “Variables”layerMemory
Section titled “layerMemory”
constlayerMemory:Layer.Layer<Leases>
Defined in: src/Leases.ts:37
makePostgres
Section titled “makePostgres”
constmakePostgres: (…args) =>Effect<{acquire(name):Effect<Lease,never,Scope>; },never,Scope|SqlClient>
Defined in: src/Leases.ts:70
Leases on PostgreSQL advisory locks, pg_try_advisory_lock on a hash of the
name. The locks belong to one connection that the service reserves from the
client’s pool for as long as anything competes, so a process holds them until
it gives them up or its connection closes: when it dies, the database releases
them and a standby takes over at its next attempt.
A holder whose connection fails stops at its next check, up to interval
later, while a standby may already have started: handlers can run in two
processes for that long.
Parameters
Section titled “Parameters”…[options?: PostgresOptions]
Returns
Section titled “Returns”Effect<{ acquire(name): Effect<Lease, never, Scope>; }, never, Scope | SqlClient>
memory
Section titled “memory”
constmemory:Leases["Service"]
Defined in: src/Leases.ts:35
Leases that are always held. It is the default of ViewModel.layer, for a
single process or for view models that keep their data in that process.
Functions
Section titled “Functions”layerPostgres()
Section titled “layerPostgres()”layerPostgres(
options?):Layer<Leases,never,SqlClient>
Defined in: src/Leases.ts:156
Leases on PostgreSQL advisory locks, see makePostgres.
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”Layer<Leases, never, SqlClient>