简体   繁体   English

回调队列(调试器)内部是什么?

[英]What is inside Callback queue (debugger)?

I would like to know how is it possible to know the content of the callback queue. 我想知道如何知道回调队列的内容。
For example, if you consider the following Javascript code : 例如,如果考虑以下Javascript代码:

<script>
    console.clear();   
    setTimeout( function () {console.log("Hello ")},5000);      
    console.log("What is inside Callback Queue ? ");        
</script> 

Is there a mean to print the content of the callback queue to the console ? 是否有将回调队列的内容打印到控制台的方法?
If not possible in such that way, is it possible with a debugger by adding a break point to the line console.log("What is inside ...?"); 如果无法通过这种方式,调试器是否可以通过在console.log("What is inside ...?");添加断点来实现console.log("What is inside ...?"); (I tried with Firefox debugger but I did not manage to do it) (我尝试使用Firefox调试器,但没有做到)
Or another solution ? 还是其他解决方案? Thanks for answer. 感谢您的回答。

The performance tab of the browser's developer tools contains all the informations needed. 浏览器开发人员工具的“性能”选项卡包含所有需要的信息。 Do the following: 请执行下列操作:

  1. Filter markers : function call (only to avoid a lot of informations) 过滤标记:函数调用(仅避免大量信息)

  2. Start Recording 开始录音

  3. Reload (CTRL + R) 重新加载(CTRL + R)

  4. Stop Recording (With my example, when Hello is printed to the console) 停止记录(以我的示例为例,将Hello打印到控制台时)

In the waterfall, Click on the mark that appears after 5000ms (with my example) and useful informations are displayed in the right pane. 在瀑布中,单击5000ms之后出现的标记(以我的示例为例),并且有用的信息显示在右窗格中。

While I'm not sure what your final goal is, you can wrap the function you're calling with the following wrapper function, which prints to the log whenever a function is being enqueued: 虽然我不确定您的最终目标是什么,但是可以使用以下wrapper函数wrapper正在调用的函数,该函数在排队时会打印到日志中:

 function wrapper(func) { console.log(`'${func.name}' was enqueued`); return func; } function foo() { console.log('Hello') } setTimeout(wrapper(foo), 5000); 

You can use a similar mechanism to maintain an array that'll contain all the functions that are currently waiting. 您可以使用类似的机制来维护一个数组,该数组将包含当前正在等待的所有函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM