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
| Function | Description |
|---|---|
| createResettableResource | Creates ResettableResource. |
| createSharedResource | Creates SharedResource. |
| createSharedResourceByKey | Creates SharedResourceByKey. |
| createSharedResourceByKeyWithClaims | Creates SharedResourceByKeyWithClaims. |
Interfaces
| Interface | Description |
|---|---|
| ClaimLease | An owned lease on the resource-retains added by one claim operation. |
| Lease | An owned lease on a shared Resource. |
| ResettableResource | A Resource reset in place. |
| SharedResource | Shared Resource. |
| SharedResourceByKey | Shared Resources keyed by logical identity. |
| SharedResourceByKeyOptions | Options for createSharedResourceByKey. |
| SharedResourceByKeySnapshot | Snapshot returned by SharedResourceByKey.snapshot. |
| SharedResourceByKeyWithClaims | Shared keyed Resources retained through claims. |
| SharedResourceByKeyWithClaimsOptions | Options for createSharedResourceByKeyWithClaims. |
| SharedResourceByKeyWithClaimsSnapshot | Snapshot returned by SharedResourceByKeyWithClaims.snapshot. |
| SharedResourceOptions | Options for createSharedResource. |
| SharedResourceSnapshot | Snapshot returned by SharedResource.snapshot. |
Type Aliases
| Type Alias | Description |
|---|---|
| BorrowedResource | Borrowed Resource. |
| Resource | Disposable resource. |