* Put an item in its block, opening the run it belongs to: work registered to * run later, and calls started together, are not the sequence they are written * in and say so rather than pretending.
(block: WireBlock, item: WireItem, site: ProgramSite)
| 321 | * in and say so rather than pretending. |
| 322 | */ |
| 323 | function place(block: WireBlock, item: WireItem, site: ProgramSite): void { |
| 324 | const run = runFor(site); |
| 325 | if (run === null) { |
| 326 | block.push(item); |
| 327 | return; |
| 328 | } |
| 329 | const last = block[block.length - 1]; |
| 330 | if (last && last.kind === 'block' && last.block === run.block && last.by === run.by) { |
| 331 | last.body.push(item); |
| 332 | return; |
| 333 | } |
| 334 | block.push({ kind: 'block', block: run.block, ...(run.by ? { by: run.by } : {}), body: [item] }); |
| 335 | } |
| 336 | |
| 337 | /** The run a site belongs to — registered to run later, started together — or null for plain sequence. */ |
| 338 | function runFor(site: ProgramSite): { block: 'later' | 'together'; by?: string } | null { |