[英]details of console.trace() with async events
recursive setTimeout(), with console.trace() suggests growing call-stack递归 setTimeout(),console.trace() 建议增加调用堆栈
I've added a console.trace() within a recursive setTimeout() and it suggests a growing call stack.我在递归 setTimeout() 中添加了一个 console.trace() ,它表明调用堆栈在增长。 Is console.trace() showing more than the call stack?
console.trace() 显示的不仅仅是调用堆栈吗?
Here is my sample recursive setTimeout..这是我的示例递归 setTimeout..
export function loop()
{
console.log(' start loop');
let myPromise = new Promise((resolve,reject)=>
{
if (window.counter > 100)
{
return;
}
window.counter = window.counter+1;
console.log(' counter:' + window.counter);
console.log('--trace start--');
console.trace();
console.log('--trace end--');
setTimeout(()=>
{
console.log('timeout expired');
resolve("done");
console.log('return from resolve.')
},500);
});
console.log(' created promise');
console.log(' resolving promise then');
myPromise.then((msg)=>
{
console.log(' next timeout');
loop();
console.log(' return from loop 1')
})
}
Here is the index.html to go with the above 'loop.js'这是带有上述“loop.js”的 index.html 到 go
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h3> Test </h3>
<script type="module">
import {loop} from "./loop.js"
window.addEventListener('load',(e)=>
{
window.counter=0;
console.log(' initial load');
loop();
})
</script>
</body>
</html>
I found that the case below explains how stack.trace() reports a 'trail' of calls including records from async event calls.我发现下面的案例解释了 stack.trace() 如何报告调用的“踪迹”,包括来自异步事件调用的记录。 So the recursive setTimeout() does not create ever-growing call stacks.
所以递归 setTimeout() 不会创建不断增长的调用堆栈。
[Stack Overflow] console.trace() method giving different outputs in synchronous and asynchronous closed function calls [堆栈溢出] console.trace() 方法在同步和异步关闭的 function 调用中给出不同的输出
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.