updateAssets

View sourceupdateAssets(world: World): Promise<void>

Processes one batch of queued loads and saves for the world’s AssetServer.

AssetServerPlugin registers this function directly in the repeating AppSchedule.Update schedule’s CoreSystems.PostMain group. It resolves the world’s AssetServer, TypeRegistry, and typed result-event resources, drains both server queues, and processes the drained load batch before the drained save batch. A request queued while a batch is being processed belongs to the next update, because queue draining replaces the server’s pending queue before the asynchronous work starts.

Loads are resolved by the asset type ID and the path extension through AssetServer#getImporter. The system fetches the path, requires an OK response, and passes the response and TypeRegistry to Importer#deserialize. A truthy imported value is written to the registered Assets pool at the requested asset ID; only then is its LoadState changed to Loaded and an AssetLoadSuccess event written. A missing importer, unsuccessful response, falsy imported value, missing asset pool, or thrown error changes that request to Failed and writes AssetLoadFail; the system then continues with the next load. Failure text is taken from a thrown string or Error.message, with a generic fallback for other values.

Saves with a pre-existing request reason immediately write AssetLoadFail with AssetLoadOperation.Saving. Other saves read the asset from its typed pool, resolve an Exporter by asset type and path extension, serialize with the TypeRegistry, and send the result with fetch(path, { method: 'POST', body }). An OK response writes AssetSaveSuccess; missing assets, exporter lookup failures, serialization or request failures write a saving AssetLoadFail and do not mutate the asset pool or load metadata. Save failures also do not stop later saves in the drained batch.

The typed result-event resources are the Events resources created by the nested event plugins in AssetServerPlugin; this system only writes their events. Missing required resources or failures while draining the queues occur before request-level try blocks and therefore reject the system call.

Examples

class Texture {}

function requestTexture(world) {
  const server = world.getResource(AssetServer)
  return server.load(Texture, '/textures/player.png')
}

function queueConfiguredTexture(world) {
  // AssetPlugin, an importer for `png`, and AssetServerPlugin are configured.
  // AssetServerPlugin runs updateAssets in Update/PostMain automatically.
  return requestTexture(world)
}

Parameters

NameDescriptionDefault
world

World containing the AssetServer, TypeRegistry, and typed load/save result-event resources.

—

Returns

Resolves after this update’s drained load and save requests have been processed.