You will create a second pump during execution. Its collection membership will trigger the existing work definition.
Create the Generator source
Create generator.workspec.js:
// @ts-check
/// <reference types="workspec/workspec-generator" />
WorkSpec.onUpdate(({ time, create }) => {
if (time !== 483) {
return;
}
create({
id: "pump_b",
type: "product",
name: "Pump B",
location: "intake",
properties: { quantity: 1, state: "awaiting_inspection" }
});
});The runtime expresses 08:03 as elapsed minute 483. Generator callbacks receive elapsed minutes in time.
Validate the generated run
Run project validation through 08:05:
npx workspec validate dynamic-start.workspec.json \
--generator generator.workspec.js \
--time 08:05Expected final line:
✓ No problems foundInspect the indirect result
Run a snapshot with the same horizon:
npx workspec snapshot dynamic-start.workspec.json \
--generator generator.workspec.js \
--time 08:05 \
--jsonThe snapshot contains pump_a and pump_b. It also contains one inspect_arrival task instance for each pump.
The runtime follows this path:
- The Generator creates
pump_bas a world object. pump_bmatches the declaredwaiting_pumpscollection.- The runtime evaluates the
inspect_arrivalwork definition. - The runtime creates a task instance correlated with
pump_b.
Keep the run deterministic
Use the Generator context's random() function when behavior needs random values. Do not use Math.random().
Supply --seed to reproduce seeded Generator behavior. The default seed is 1.
Read Generator and dynamic work for the ownership boundary. Read Generator execution order for same-time behavior.
Next step
Complete the capstone project with all four project files.