API reference › @evolu/common › Resource

Concurrency-safe helpers for efficient reuse and replacement of disposable resources.

Replacement policies

Replacing a live resource has two policies.

Exclusive replacement disposes the current resource and then creates the next, so at most one exists and there is an observable gap with none. ResettableResource implements it. Leases do not fit this policy: a reset is requested precisely when holders are stuck on a dead resource, so waiting for them inverts the purpose, and revoking them is safe only when the resource's own API is total after disposal, in which case a lease adds nothing.

Overlapping replacement creates the next generation first and disposes the previous one when its last lease is released, so work in progress finishes on the generation it started with. It keeps the old generation when creation fails, at the cost of both existing for a while. It is not implemented. It belongs on SharedResource as an invalidate operation: mark the current generation stale, stop leasing it, dispose it on its last release, and create the next on the next acquire. Before that can ship, SharedResourceByKey must stop removing a key when its resource is disposed, and SharedResourceByKeyWithClaims must stop keeping one resource object per key for the lifetime of its claims.

Functions

FunctionDescription
createResettableResourceCreates ResettableResource.
createSharedResourceCreates SharedResource.
createSharedResourceByKeyCreates SharedResourceByKey.
createSharedResourceByKeyWithClaimsCreates SharedResourceByKeyWithClaims.

Interfaces

InterfaceDescription
ClaimLeaseAn owned lease on the resource-retains added by one claim operation.
LeaseAn owned lease on a shared Resource.
ResettableResourceA Resource reset in place.
SharedResourceShared Resource.
SharedResourceByKeyShared Resources keyed by logical identity.
SharedResourceByKeyOptionsOptions for createSharedResourceByKey.
SharedResourceByKeySnapshotSnapshot returned by SharedResourceByKey.snapshot.
SharedResourceByKeyWithClaimsShared keyed Resources retained through claims.
SharedResourceByKeyWithClaimsOptionsOptions for createSharedResourceByKeyWithClaims.
SharedResourceByKeyWithClaimsSnapshotSnapshot returned by SharedResourceByKeyWithClaims.snapshot.
SharedResourceOptionsOptions for createSharedResource.
SharedResourceSnapshotSnapshot returned by SharedResource.snapshot.

Type Aliases

Type AliasDescription
BorrowedResourceBorrowed Resource.
ResourceDisposable resource.