API reference / @jsprismarine/chunkgen / ShardedGenerationPool
Class: ShardedGenerationPool
Defined in: ShardedGenerationPool.ts:90
Runs generation tasks in workers that each own a part of the world.
The same surface as GenerationPool, so a caller can hold either.
Constructors
Constructor
new ShardedGenerationPool(
options,runner?):ShardedGenerationPool
Defined in: ShardedGenerationPool.ts:112
Parameters
options
The pipeline module, the worker count, the setup and the region size.
runner?
How to build each shard's task runner. Defaults to piscina.
Returns
ShardedGenerationPool
Properties
options
readonlyoptions:ShardedGenerationPoolOptions
Defined in: ShardedGenerationPool.ts:113
The pipeline module, the worker count, the setup and the region size.
Accessors
inFlight
Get Signature
get inFlight():
number
Defined in: ShardedGenerationPool.ts:136
How many tasks the workers are holding right now.
Returns
number
queued
Get Signature
get queued():
number
Defined in: ShardedGenerationPool.ts:141
How many tasks are waiting for a worker, across every shard and band.
Returns
number
workers
Get Signature
get workers():
number
Defined in: ShardedGenerationPool.ts:131
How many workers are up, across every shard.
Returns
number
Methods
cancel()
cancel(
wanted):number
Defined in: ShardedGenerationPool.ts:182
Drops every waiting task a predicate rejects, in every shard.
Parameters
wanted
(task) => boolean
Returns
number
How many went.
destroy()
destroy():
Promise<void>
Defined in: ShardedGenerationPool.ts:202
Stops every worker of every shard.
Returns
Promise<void>
promote()
promote(
wanted,to):number
Defined in: ShardedGenerationPool.ts:187
Moves waiting tasks up into a band, in every shard.
Parameters
wanted
(task) => boolean
to
"immediate" | "soon" | "idle"
Returns
number
How many moved.
resetStats()
resetStats():
void
Defined in: ShardedGenerationPool.ts:197
Forgets the recorded task stats of every shard.
Returns
void
run()
run(
task,priority?):Promise<GenerationResult>
Defined in: ShardedGenerationPool.ts:154
Runs one task in the worker that owns its region, or in an idle one when that worker is far enough behind.
Parameters
task
The status, the position and whatever else the body reads.
priority?
"immediate" | "soon" | "idle" = 'immediate'
Which band the task waits in. Ordered per worker, because that is where the queue is.
Returns
Promise<GenerationResult>
What the body produced.
runOnShard()
runOnShard(
shard,task,priority?):Promise<GenerationResult>
Defined in: ShardedGenerationPool.ts:171
Runs an affinity task on one exact shard, preserving that worker's local cache.
Most generation work uses ShardedGenerationPool.run's region routing and stealing. A cache-owner task must stay on its assigned shard, because moving it would rebuild the cached value on another worker.
Parameters
shard
number
Zero-based shard index.
task
The status, position and input for that worker.
priority?
"immediate" | "soon" | "idle" = 'immediate'
Which queue band the task enters.
Returns
Promise<GenerationResult>
What the owning worker produced.
Throws
RangeError when the shard index is outside this pool.
statsSnapshot()
statsSnapshot():
GenerationStatsSnapshot
Defined in: ShardedGenerationPool.ts:192
What every shard recorded, merged into one snapshot.
Returns
unavailable()
staticunavailable(options):string|undefined
Defined in: ShardedGenerationPool.ts:104
Why this process cannot run workers, or undefined when it can.
The same question GenerationPool.unavailable answers, asked of the options every shard is built with.
Parameters
options
The options this pool would be built with.
Returns
string | undefined
A sentence naming what is missing, or undefined when nothing is.