begin clock rewrite

This commit is contained in:
2024-04-20 01:58:06 +02:00
parent 9dfac1141f
commit 2304015975
7 changed files with 96 additions and 71 deletions

View File

@ -49,24 +49,23 @@ export async function tryEvaluate(application: Editor, code: File, timeout = 500
* @returns A Promise that resolves when the evaluation is complete.
*/
code.evaluations!++;
const candidateCode = code.candidate;
const cachedFunction = cache.get(candidateCode);
const cachedFunction = cache.get(code.candidate);
if (cachedFunction) {
cachedFunction.call(application.api);
return;
}
const wrappedCode = `let i = ${code.evaluations}; ${candidateCode}`;
const wrappedCode = `let i = ${code.evaluations}; ${code.candidate}`;
const isCodeValid = await Promise.race([
tryCatchWrapper(application, wrappedCode),
delay(timeout)
]);
if (isCodeValid) {
code.committed = candidateCode;
code.committed = code.candidate;
const newFunction = new Function(`"use strict"; ${codeReplace(wrappedCode)}`);
addFunctionToCache(candidateCode, newFunction);
addFunctionToCache(code.candidate, newFunction);
} else {
application.api.logOnce("Compilation error!");
await delay(100);
@ -107,3 +106,7 @@ export const evaluateOnce = async (
*/
await tryCatchWrapper(application, code);
};