voxolith

GeneratorPool

A pool of generator workers, from makeGeneratorPool. Entities come back with their buffers transferred, so the main thread owns them outright.

Defined in: engine/src/worker/pool.ts:105

Properties

PropertyModifierTypeDescriptionDefined in
cachedreadonlynumberResults that came from a worker's model cache (see serveGenerators' cache).engine/src/worker/pool.ts:149
modelKeyreadonly(model: EntityModel) => string | undefinedWhat produced a model this pool returned, as a string: the worker script's URL (hashed in production builds, so it changes with the generator code), the generator id and version, seed, parameters and context. Undefined for any other model. Deterministic generation makes it a stable name for the model's content across visits, which is what a cache of anything derived from the model needs: give it to makeInstanceLayer(target, { worker, modelKey: pool.modelKey }) and a scene worker with a cache keeps each model's encoding under it. It names the model as generated: a host that edits a model in place must not pass its key on. In development the worker URL does not change with the code, so keys stay the same across generator edits (leave derived caches off there, as for the model cache). A bound function: pass it around as it is. Works after destroy().engine/src/worker/pool.ts:163
pausedreadonlybooleanDispatching is paused.engine/src/worker/pool.ts:147
pendingreadonlynumberRequests issued but not yet settled (queued or running; aborted ones are settled).engine/src/worker/pool.ts:143
queuedreadonlynumberOf pending, the requests waiting for a worker.engine/src/worker/pool.ts:145
sizereadonlynumberNumber of workers.engine/src/worker/pool.ts:141

Methods

destroy()

destroy(): Promise<void>;

Defined in: engine/src/worker/pool.ts:139

Stop the pool: every pending request rejects at once and the pool is unusable afterwards. Workers still generating are terminated at once; idle ones first finish their model-cache writes (up to closeTimeoutMs), so the models just made are there next visit. Resolves when every worker has been terminated; callers need not wait.

Returns

Promise<void>


generate()

generate(spec: GenerateSpec, opts?: GenerateOptions): Promise<Entity>;

Defined in: engine/src/worker/pool.ts:110

Generate one entity on the next free worker. Rejects when the generator is not registered in the worker, throws, the worker dies, the request is aborted, or the pool is destroyed.

Parameters

ParameterType
specGenerateSpec
opts?GenerateOptions

Returns

Promise<Entity>


generateMany()

generateMany(specs: GenerateSpec[], opts?: 
  | GenerateManyOptions
| ((done: number, total: number) => void)): Promise<Entity[]>;

Defined in: engine/src/worker/pool.ts:116

Generate many, spread across the pool. Resolves in the order given, not the order they finish; rejects with the first failure (an abort through opts.signal rejects them all). The options apply to every request. The older form generateMany(specs, onDone) still works.

Parameters

ParameterType
specsGenerateSpec[]
opts?| GenerateManyOptions | ((done: number, total: number) => void)

Returns

Promise<Entity[]>


pause()

pause(): void;

Defined in: engine/src/worker/pool.ts:121

Stop handing queued requests to workers. Running ones finish and resolve; new requests queue. The models phase stays busy while anything is queued, since the work is still owed.

Returns

void


ready()

ready(): Promise<void>;

Defined in: engine/src/worker/pool.ts:132

Resolves once every worker has registered its generators.

Returns

Promise<void>


reprioritise()

reprioritise(fn: (spec: GenerateSpec, priority: number) => number): void;

Defined in: engine/src/worker/pool.ts:130

Give queued requests new priorities: fn gets each one's spec and current priority and returns the new one. The queue is re-sorted (keeping queue order within a priority); running requests are unaffected. One call is a sort of the queue, so a game streaming models around the player can call it whenever the player has moved far enough.

Parameters

ParameterType
fn(spec: GenerateSpec, priority: number) => number

Returns

void


resume()

resume(): void;

Defined in: engine/src/worker/pool.ts:123

Start dispatching again after GeneratorPool.pause.

Returns

void

On this page