voxolith

serveGenerators()

Serve generate requests on this worker until it is terminated. Call after registering the generators this worker should offer: the pool sends a generator id, and a function cannot cross the worker boundary, so the registry must be filled here. Posts a ready message listing the registered ids,...

function serveGenerators(opts?: ServeOptions | WorkerScope): void;

Defined in: engine/src/worker/serve.ts:86

Serve generate requests on this worker until it is terminated. Call after registering the generators this worker should offer: the pool sends a generator id, and a function cannot cross the worker boundary, so the registry must be filled here. Posts a ready message listing the registered ids, then answers each request with the entity (packed into one buffer and transferred, see PackedEntity; the pool unpacks it) or an error. Each answer also names what made the model (key: this worker's URL, generator id and version, seed, params and context), which the pool hands out as GeneratorPool.modelKey.

With cache, models are kept in IndexedDB keyed by generator id and version, seed, params and context, salted with this worker's URL, so a production build (which hashes the URL) never serves a model made by older generator code. Writes finish after the result is posted; the pool's destroy() asks the worker to finish them (close) before terminating it.

Parameters

ParameterTypeDescription
opts?ServeOptions | WorkerScopeOptions, or the worker scope itself (the older form).

Returns

void

Example

// gen.worker.ts
import { registerTreeGenerators } from "@voxolith/gen-tree";
import { serveGenerators } from "@voxolith/engine/worker";
registerTreeGenerators();
serveGenerators({ cache: import.meta.env.DEV ? undefined : "voxolith-models" });

On this page