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.
This commit is contained in:
parent
3d661793ef
commit
0241b7b469
|
|
@ -15,6 +15,7 @@ import * as xpromise from "./xpromise.mjs"
|
||||||
|
|
||||||
|
|
||||||
self.onmessage = async function (ev) {
|
self.onmessage = async function (ev) {
|
||||||
|
console.info("DBUG:WW:OnMessage started...")
|
||||||
tconsole.console_redir()
|
tconsole.console_redir()
|
||||||
try {
|
try {
|
||||||
await xpromise.evalWithPromiseTracking(ev.data.code);
|
await xpromise.evalWithPromiseTracking(ev.data.code);
|
||||||
|
|
@ -23,4 +24,5 @@ self.onmessage = async function (ev) {
|
||||||
}
|
}
|
||||||
tconsole.console_revert()
|
tconsole.console_revert()
|
||||||
self.postMessage({ id: ev.data.id, name: ev.data.name, data: tconsole.gConsoleStr})
|
self.postMessage({ id: ev.data.id, name: ev.data.name, data: tconsole.gConsoleStr})
|
||||||
|
console.info("DBUG:WW:OnMessage done")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,22 +13,25 @@
|
||||||
* Eval which allows promises generated by the evald code to be tracked.
|
* Eval which allows promises generated by the evald code to be tracked.
|
||||||
* @param {string} codeToEval
|
* @param {string} codeToEval
|
||||||
*/
|
*/
|
||||||
export function evalWithPromiseTracking(codeToEval) {
|
export async function evalWithPromiseTracking(codeToEval) {
|
||||||
const _Promise = globalThis.Promise;
|
const _Promise = globalThis.Promise;
|
||||||
/** @type {any[]} */
|
/** @type {any[]} */
|
||||||
const trackedPromises = [];
|
const trackedPromises = [];
|
||||||
|
|
||||||
const Promise = function ( /** @type {PromiseExecutor} */ executor) {
|
const Promise = function ( /** @type {PromiseExecutor} */ executor) {
|
||||||
|
console.info("WW:PT:Promise")
|
||||||
const promise = new _Promise(executor);
|
const promise = new _Promise(executor);
|
||||||
trackedPromises.push(promise);
|
trackedPromises.push(promise);
|
||||||
|
|
||||||
promise.then = function (...args) {
|
promise.then = function (...args) {
|
||||||
|
console.info("WW:PT:Then")
|
||||||
const newPromise = _Promise.prototype.then.apply(this, args);
|
const newPromise = _Promise.prototype.then.apply(this, args);
|
||||||
trackedPromises.push(newPromise);
|
trackedPromises.push(newPromise);
|
||||||
return newPromise;
|
return newPromise;
|
||||||
};
|
};
|
||||||
|
|
||||||
promise.catch = function (...args) {
|
promise.catch = function (...args) {
|
||||||
|
console.info("WW:PT:Catch")
|
||||||
const newPromise = _Promise.prototype.catch.apply(this, args);
|
const newPromise = _Promise.prototype.catch.apply(this, args);
|
||||||
trackedPromises.push(newPromise);
|
trackedPromises.push(newPromise);
|
||||||
return newPromise;
|
return newPromise;
|
||||||
|
|
@ -42,5 +45,7 @@ export function evalWithPromiseTracking(codeToEval) {
|
||||||
|
|
||||||
eval(codeToEval);
|
eval(codeToEval);
|
||||||
|
|
||||||
|
//await Promise(resolve=>setTimeout(resolve, 0));
|
||||||
|
//return _Promise.allSettled(trackedPromises);
|
||||||
return _Promise.all(trackedPromises);
|
return _Promise.all(trackedPromises);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue