Skip to content

Commit 7dc999f

Browse files
committed
SimpleChatTC:TrapPromise: log the trapping
also possible refinement wrt trapping, if needed, added as comment all or allSettled to use or not is the question. whether to wait for a round trip through the related event loop or not is also a question.
1 parent 99b04ec commit 7dc999f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

tools/server/public_simplechat/toolsworker.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as xpromise from "./xpromise.mjs"
1515

1616

1717
self.onmessage = async function (ev) {
18+
console.info("DBUG:WW:OnMessage started...")
1819
tconsole.console_redir()
1920
try {
2021
await xpromise.evalWithPromiseTracking(ev.data.code);
@@ -23,4 +24,5 @@ self.onmessage = async function (ev) {
2324
}
2425
tconsole.console_revert()
2526
self.postMessage({ id: ev.data.id, name: ev.data.name, data: tconsole.gConsoleStr})
27+
console.info("DBUG:WW:OnMessage done")
2628
}

tools/server/public_simplechat/xpromise.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,25 @@
1313
* Eval which allows promises generated by the evald code to be tracked.
1414
* @param {string} codeToEval
1515
*/
16-
export function evalWithPromiseTracking(codeToEval) {
16+
export async function evalWithPromiseTracking(codeToEval) {
1717
const _Promise = globalThis.Promise;
1818
/** @type {any[]} */
1919
const trackedPromises = [];
2020

2121
const Promise = function ( /** @type {PromiseExecutor} */ executor) {
22+
console.info("WW:PT:Promise")
2223
const promise = new _Promise(executor);
2324
trackedPromises.push(promise);
2425

2526
promise.then = function (...args) {
27+
console.info("WW:PT:Then")
2628
const newPromise = _Promise.prototype.then.apply(this, args);
2729
trackedPromises.push(newPromise);
2830
return newPromise;
2931
};
3032

3133
promise.catch = function (...args) {
34+
console.info("WW:PT:Catch")
3235
const newPromise = _Promise.prototype.catch.apply(this, args);
3336
trackedPromises.push(newPromise);
3437
return newPromise;
@@ -42,5 +45,7 @@ export function evalWithPromiseTracking(codeToEval) {
4245

4346
eval(codeToEval);
4447

48+
//await Promise(resolve=>setTimeout(resolve, 0));
49+
//return _Promise.allSettled(trackedPromises);
4550
return _Promise.all(trackedPromises);
4651
}

0 commit comments

Comments
 (0)