API reference › @evolu/common › Resource › createResettableResource

function createResettableResource<T extends Resource, D>(
  create: Task<T, never, D>,
): Task<ResettableResource<T>, never, D>;

Defined in: packages/common/src/Resource.ts:646

Creates ResettableResource.

The first resource is created before this Task returns; if that creation aborts, nothing is left running. If the caller's Fiber aborts during initial creation, this Task waits for creation to settle, disposes any created resource, and returns the abort instead of a resource.

The create Task must not fail: the previous resource is already disposed when it runs, so a failure would leave nothing to fall back to. Handle recoverable failures inside create, or return a resource whose state models them.

The resource's own API must model its not-ready state, as a reconnecting connection models "connecting": get returns undefined during a reset, and callers treat that absence the same way. A resource whose API assumes readiness gains nothing here; every caller would rebuild that state around it.

As with createSharedResource, a returned resource must be live and independently owned, and create runs on a Run created from the Run that executes this Task, so dependencies are captured at creation time.

Every successful create invocation must return a fresh object identity, never one returned earlier. A reset skips when the observed resource is no longer current, and that comparison is by identity; a reused object makes a stale observation match the replacement and reset it again.

A reset runs create and the resource's disposer while holding a non-reentrant lock. Neither may directly or transitively await another reset of this ResettableResource, because that reset waits for the same lock.