feat(canvas): recover admitted copy preparation from immutable snapshots
This commit is contained in:
@@ -4,6 +4,7 @@ import { clone, fault, freeze } from '../canvas-core/values.ts';
|
||||
|
||||
export type DuplicateScheduling = {
|
||||
readonly signal?: AbortSignal;
|
||||
readonly checkpoint?: (steps:number) => Promise<void>;
|
||||
readonly frameBudgetMs?: number;
|
||||
readonly maxStepsPerSlice?: number;
|
||||
readonly now?: () => number;
|
||||
@@ -24,6 +25,7 @@ export async function planDuplicateAsync(document: Document, registry: Registry,
|
||||
// Capture caller-owned small inputs before the first await. Document/registry are immutable core snapshots.
|
||||
const targets = freeze(clone(selection)), settings: DuplicateOptions = Object.freeze({ createId: options.createId, ...(options.worldOffset ? {worldOffset: freeze(clone(options.worldOffset))} : {}), ...(options.mapping ? {mapping: freeze(clone(options.mapping))} : {}) });
|
||||
const steps = planDuplicateSteps(document, registry, targets, settings);
|
||||
let completedSteps=0;
|
||||
try {
|
||||
while (true) {
|
||||
check();
|
||||
@@ -33,9 +35,10 @@ export async function planDuplicateAsync(document: Document, registry: Registry,
|
||||
const step = steps.next();
|
||||
check();
|
||||
if (step.done) return step.value;
|
||||
count++;
|
||||
count++;completedSteps++;
|
||||
} while (count < limit && now() - start < budget);
|
||||
await yieldTask();
|
||||
if(scheduling.checkpoint)await scheduling.checkpoint(completedSteps);
|
||||
check();await yieldTask();
|
||||
}
|
||||
} finally {
|
||||
// Release snapshot references after cancellation or host scheduling failures.
|
||||
|
||||
Reference in New Issue
Block a user