Documentation
    Preparing search index...

    Class AssetManager<TSignal>

    Deduplicating, reference-counted asset cache (§76).

    See the module comment for cache identity, coalescing, failure, and disposal semantics — they are the contract, not implementation detail.

    Type Parameters

    • TSignal = never

    Implements

    Index
    • get canAbortTransport(): boolean

      Whether cancelling a load also cancels its request — that is, whether an AssetManagerOptions.abortController was injected (§76).

      Presence is the capability: AssetManager.load's signal behaves the same either way, so this is the honest answer to "did the socket actually close?", not a switch that changes the API.

      Returns boolean

    • get canDecodeInWorker(): boolean

      Whether { decodeInWorker: true } will post bytes to a Worker — that is, whether an AssetManagerOptions.workerFactory was injected.

      Returns boolean

    • get canHashContent(): boolean

      Whether this manager can compute content hashes (§76) — that is, whether an AssetManagerOptions.digest was injected or the runtime supplied one (crypto.subtle, absent in an insecure browser context).

      Presence is the capability, exactly as canAbortTransport is. The difference is what a missing one does: cancellation degrades quietly to promise-level semantics, while a hash that cannot be computed refuses, because a verification that silently passes is worse than none.

      Returns boolean

    • get isDisposed(): boolean

      Whether dispose has been called.

      Returns boolean

    • get maximumBytes(): number

      The effective §96 input-size limit in bytes (diagnostics and tests).

      Returns number

    • get size(): number

      Number of cache slots, pending loads included.

      Returns number

    • get timeoutSeconds(): number

      The effective §96 load deadline in seconds (diagnostics and tests).

      Returns number

    • Evicts every entry regardless of reference count, disposing the disposable ones in reverse insertion order (disposeAll, §83). Pending loads are marked so they dispose on settle instead of re-entering the cache.

      If any dispose() throws, every remaining asset is still disposed and the first failure is rethrown — disposeAll's contract.

      Returns void

    • The content hash recorded for (url, loader) (§76), or undefined when the entry is absent, still loading, or was loaded without AssetLoadOptions.hashContent.

      This is the value §79's manifest records beside the URL. Like get it is a peek: it never changes the reference count and never triggers a load.

      Parameters

      Returns string | undefined

    • The recorded children of url, in registration order. A URL with no edges returns an empty array — never undefined.

      Parameters

      • url: string

      Returns readonly string[]

    • Clears the cache and refuses further loads. Idempotent; queries (get, has, refCount, release) stay callable and answer as they would for an empty cache, so teardown order between an owner and its assets cannot turn into a crash.

      Returns void

    • The cached asset for (url, loader), or undefined if it is absent or still loading. Does not change the reference count.

      Type Parameters

      • T

      Parameters

      Returns T | undefined

    • Whether a settled asset is cached for (url, loader). A load still in flight is false here — it coalesces, but there is nothing to hand out.

      Parameters

      Returns boolean

    • Loads url through loader, or joins the load already in flight for that pair, or returns the cached asset.

      Increments the reference count by one in all three cases; pair every call with one release. A rejection leaves nothing cached, so the same call retries.

      options.signal cancels this call (§76): the promise rejects, the reference it took is handed back — so an aborted load must not be released — and the request is abandoned once no waiter is left. See the module comment's three cancellation rules.

      Type Parameters

      • T

      Parameters

      Returns Promise<T>

      FourError INVALID_APPLICATION_STATE if the manager is disposed, or if it has no fetch (none injected and no global one) and would have had to perform IO.

      FourError ASSET_LOAD_FAILED (asynchronously) on transport failure, a non-ok response, a loader that could not decode, or cancellation (context.reason === "aborted").

    • Loads rootUrl and walks declared + registered dependencies (§76).

      Type Parameters

      • T

      Parameters

      Returns Promise<AssetGraph<T>>

      The root asset and a map of every URL the walk loaded (root included). Each map entry holds one reference.

    • Loads registered children first, then url (§76).

      Children use AssetGraphLoadOptions.dependencyLoader when one is given, otherwise loader. After the parent settles, any { dependencies: string[] } on the result are registered and loaded too. Cycles refuse with ASSET_LOAD_FAILED / context.reason === "dependency-cycle".

      Each URL takes one load reference; the caller releases the parent (and any child it intends to drop) itself.

      Type Parameters

      • T

      Parameters

      Returns Promise<T>

    • The live reference count for (url, loader), or 0 when there is no entry. Diagnostics and tests; the manager never needs it.

      Parameters

      Returns number

    • Records a parent→child edge for loadWithDependencies / loadGraph (§76). Duplicate edges are ignored. A self-edge is a programming error and throws INVALID_APPLICATION_STATE.

      Parameters

      • parentUrl: string
      • childUrl: string

      Returns void

    • Drops one reference. On the last one the entry is evicted and a Disposable asset is disposed (§83).

      Parameters

      Returns boolean

      true if this call released the last reference (for a load still in flight, disposal then happens when it settles), false if references remain or there was no entry.

    • Yields the response body as Uint8Array chunks (§76 streaming).

      Uses body.getReader when the transport exposes one; otherwise yields the whole arrayBuffer() once. Does not touch the cache or take a reference — it is a raw read, and the caller is the only consumer.

      Honours AssetManagerOptions.maximumBytes, the §96 deadline, and options.signal with the same codes as load.

      Parameters

      Returns AsyncIterable<Uint8Array<ArrayBufferLike>>

    • Drops one recorded edge. Unknown pairs are a no-op.

      Parameters

      • parentUrl: string
      • childUrl: string

      Returns boolean

      true if an edge was removed.

    • Subscribes to changes for url through the injected AssetManagerOptions.watch (§76 hot reload).

      Parameters

      • url: string
      • listener: (url: string) => void

      Returns () => void

      An unsubscriber. Calling it twice is a no-op.

      FourError INVALID_APPLICATION_STATE if no watch was injected, or if the manager is disposed.