auto-save 2026-05-20 23:53 (~2)
This commit is contained in:
@@ -1853,6 +1853,13 @@
|
|||||||
"message": "auto-save 2026-05-20 22:48 (~2)",
|
"message": "auto-save 2026-05-20 22:48 (~2)",
|
||||||
"hash": "a3d0c97",
|
"hash": "a3d0c97",
|
||||||
"files_changed": 2
|
"files_changed": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ts": "2026-05-20T22:54:10+08:00",
|
||||||
|
"type": "commit",
|
||||||
|
"message": "auto-save 2026-05-20 22:54 (~3)",
|
||||||
|
"hash": "7697754",
|
||||||
|
"files_changed": 3
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -389,24 +389,38 @@ export async function generateAssetPack(opts: {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
while (remainingTemplates.length > 0) {
|
const inFlight = new Set<Promise<void>>();
|
||||||
const readyTemplates = remainingTemplates
|
function takeReadyTemplate(): AssetTemplate | undefined {
|
||||||
.filter(template => !template.anchorTemplateId || generatedTemplateIds.has(template.anchorTemplateId))
|
const index = remainingTemplates.findIndex(template => !template.anchorTemplateId || generatedTemplateIds.has(template.anchorTemplateId));
|
||||||
.slice(0, PACK_ASSET_CONCURRENCY);
|
if (index === -1) return undefined;
|
||||||
if (!readyTemplates.length) {
|
const [template] = remainingTemplates.splice(index, 1);
|
||||||
throw new Error(`template anchor cycle or missing root: ${remainingTemplates.map(template => template.id).join(', ')}`);
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const template of readyTemplates) {
|
function scheduleReadyTemplates() {
|
||||||
remainingTemplates.splice(remainingTemplates.indexOf(template), 1);
|
while (inFlight.size < PACK_ASSET_CONCURRENCY) {
|
||||||
}
|
const template = takeReadyTemplate();
|
||||||
|
if (!template) return;
|
||||||
await Promise.all(readyTemplates.map(async template => {
|
const task = (async () => {
|
||||||
const asset = await createAsset(template);
|
const asset = await createAsset(template);
|
||||||
assets.push(asset);
|
assets.push(asset);
|
||||||
generatedTemplateIds.add(template.id);
|
generatedTemplateIds.add(template.id);
|
||||||
await opts.onProgress?.(pack);
|
await opts.onProgress?.(pack);
|
||||||
}));
|
})();
|
||||||
|
inFlight.add(task);
|
||||||
|
task.then(
|
||||||
|
() => inFlight.delete(task),
|
||||||
|
() => inFlight.delete(task),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (remainingTemplates.length > 0 || inFlight.size > 0) {
|
||||||
|
scheduleReadyTemplates();
|
||||||
|
if (inFlight.size === 0) {
|
||||||
|
throw new Error(`template anchor cycle or missing root: ${remainingTemplates.map(template => template.id).join(', ')}`);
|
||||||
|
}
|
||||||
|
await Promise.race(inFlight);
|
||||||
}
|
}
|
||||||
|
|
||||||
const templateOrder = new Map(templates.map((template, index) => [template.id, index]));
|
const templateOrder = new Map(templates.map((template, index) => [template.id, index]));
|
||||||
|
|||||||
Reference in New Issue
Block a user