Skip to content

Commit 788a9e4

Browse files
committed
SimpleChatTC: Allow await in generated code that will be evald
1 parent 5d76493 commit 788a9e4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tools/server/public_simplechat/xpromise.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export async function evalWithPromiseTracking(codeToEval) {
2525
const promise = new _Promise(executor);
2626
trackedPromises.push(promise);
2727

28+
// @ts-ignore
2829
promise.then = function (...args) {
2930
console.info("WW:PT:Then")
3031
const newPromise = _Promise.prototype.then.apply(this, args);
@@ -47,12 +48,15 @@ export async function evalWithPromiseTracking(codeToEval) {
4748

4849
const fetch = function(/** @type {any[]} */ ...args) {
4950
console.info("WW:PT:Fetch")
51+
// @ts-ignore
5052
const fpromise = _fetch(args);
5153
trackedPromises.push(fpromise)
5254
return fpromise;
5355
}
5456

55-
eval(codeToEval);
57+
//let tf = new Function(codeToEval);
58+
//await tf()
59+
await eval(`(async () => { ${codeToEval} })()`);
5660

5761
//await Promise(resolve=>setTimeout(resolve, 0));
5862
//return _Promise.allSettled(trackedPromises);

0 commit comments

Comments
 (0)