API reference › @evolu/common › Resource › SharedResource
Defined in: packages/common/src/Resource.ts:164
Shared Resource.
Lazily acquires the underlying resource on the first acquire call, shares it across callers, and disposes it when the last caller releases it.
Calls to release must be balanced with successful calls to acquire. Releasing more times than acquired is a programmer error checked with assert.
Extends
Methods
[asyncDispose]()
asyncDispose: PromiseLike<void>;
Defined in: node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.esnext.disposable.d.ts:40
Inherited from
AsyncDisposable.[asyncDispose]
Properties
acquire
readonly acquire: Task<BorrowedResource<T>, never, D>;
Defined in: packages/common/src/Resource.ts:188
Acquires a shared reference.
The first call lazily creates the resource. Later calls reuse the same resource until the final release starts the final disposal path. Disposal happens immediately by default, or after idleDisposeAfter elapses when configured.
Once started, acquire runs to completion even if the caller aborts its Fiber. Always await the result. A successful result still counts as an acquired lease and must later be balanced with release.
get
readonly get: () =>
| BorrowedResource<T>
| undefined;
Defined in: packages/common/src/Resource.ts:172
Returns the current resource, or undefined if absent.
getCount
readonly getCount: Task<number & Brand<"Int"> & Brand<"NonNegative">, never, D>;
Defined in: packages/common/src/Resource.ts:205
Returns the current acquire count.
release
readonly release: Task<void, never, D>;
Defined in: packages/common/src/Resource.ts:202
Releases one previously acquired shared reference.
When the last acquired reference is released, the current resource is disposed immediately by default. If idleDisposeAfter is set, disposal is scheduled instead and a new acquire during that delay reuses the current resource.
Once started, release runs to completion even if the caller aborts its Fiber. Always await the result instead of assuming no cleanup happened.
snapshot
readonly snapshot: () => SharedResourceSnapshot;
Defined in: packages/common/src/Resource.ts:169
Returns the current shared-resource state for monitoring/debugging.