Skip to content

StorageLease

Single-owner leases for storage. A Session assumes it is the only writer of its storage; two owners of one SQLite file, JSONL directory or MemoryStore would interleave commits and corrupt it. Each storage layer acquires a lease when it opens and releases it when its scope closes, so a second opener fails fast with StorageLeaseHeld instead.

NodeStorageLease.lockFile is the default of the file-backed storages (NodeSqliteStorage, JsonlStorage). inMemory guards in-process resources such as a MemoryStore. none opts out, for hosts that coordinate ownership themselves.

import { JsonlStorage, StorageLease } from "@effective-harness/core"
// The default lease: the lock file `./.harness/LOCK`, removed when the layer closes.
const StorageLive = JsonlStorage.layer({ directory: "./.harness" })
// Ownership coordinated elsewhere.
const Unleased = JsonlStorage.layer({ directory: "./.harness", lease: StorageLease.none })

Since v0.0.0


The lease port: exclusive ownership of one named resource for the lifetime of a scope.

Signature

export interface StorageLease {
/** Acquire `resource` until the scope closes; fail with `StorageLeaseHeld` when another owner holds it. */
readonly acquire: (resource: string) => Effect.Effect<void, StorageLeaseHeld | StorageFailure, Scope.Scope>
}

Source

Since v0.0.0

An in-process lease table: a resource can be held once at a time among the users of this value.

Signature

declare const inMemory: () => {
readonly acquire: (resource: string) => Effect.Effect<void, StorageLeaseHeld, Scope.Scope>
}

Source

Since v0.0.0

No lease: every acquisition succeeds.

Signature

declare const none: StorageLease

Source

Since v0.0.0