SimpleChatTC: Allow await in generated code that will be evald

This commit is contained in:
hanishkvc 2025-10-15 22:52:07 +05:30
parent 92e5b2133e
commit 77d3e43cb4
1 changed files with 5 additions and 1 deletions

View File

@ -25,6 +25,7 @@ export async function evalWithPromiseTracking(codeToEval) {
const promise = new _Promise(executor);
trackedPromises.push(promise);
// @ts-ignore
promise.then = function (...args) {
console.info("WW:PT:Then")
const newPromise = _Promise.prototype.then.apply(this, args);
@ -47,12 +48,15 @@ export async function evalWithPromiseTracking(codeToEval) {
const fetch = function(/** @type {any[]} */ ...args) {
console.info("WW:PT:Fetch")
// @ts-ignore
const fpromise = _fetch(args);
trackedPromises.push(fpromise)
return fpromise;
}
eval(codeToEval);
//let tf = new Function(codeToEval);
//await tf()
await eval(`(async () => { ${codeToEval} })()`);
//await Promise(resolve=>setTimeout(resolve, 0));
//return _Promise.allSettled(trackedPromises);