SimpleChatTC:Promises: trap normal fetch (dont care await or not)
This commit is contained in:
parent
0241b7b469
commit
92e5b2133e
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
export async function evalWithPromiseTracking(codeToEval) {
|
export async function evalWithPromiseTracking(codeToEval) {
|
||||||
const _Promise = globalThis.Promise;
|
const _Promise = globalThis.Promise;
|
||||||
|
const _fetch = globalThis.fetch
|
||||||
|
|
||||||
/** @type {any[]} */
|
/** @type {any[]} */
|
||||||
const trackedPromises = [];
|
const trackedPromises = [];
|
||||||
|
|
||||||
|
|
@ -43,6 +45,13 @@ export async function evalWithPromiseTracking(codeToEval) {
|
||||||
Promise.prototype = _Promise.prototype;
|
Promise.prototype = _Promise.prototype;
|
||||||
Object.assign(Promise, _Promise);
|
Object.assign(Promise, _Promise);
|
||||||
|
|
||||||
|
const fetch = function(/** @type {any[]} */ ...args) {
|
||||||
|
console.info("WW:PT:Fetch")
|
||||||
|
const fpromise = _fetch(args);
|
||||||
|
trackedPromises.push(fpromise)
|
||||||
|
return fpromise;
|
||||||
|
}
|
||||||
|
|
||||||
eval(codeToEval);
|
eval(codeToEval);
|
||||||
|
|
||||||
//await Promise(resolve=>setTimeout(resolve, 0));
|
//await Promise(resolve=>setTimeout(resolve, 0));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue