如何列出所有承诺 [英] How to list all promisses
问题描述
我正在阅读 Promise.all() 指南 但似乎不是我需要的,我需要做一些像 console.log(Promise.LIST_OF_ALL_CREATED)
并查看所有承诺的列表(数组或对象).我不知道承诺 ID 或变量名称.
I am reading Promise.all() guide but not seems what I need, I need to do something as console.log(Promise.LIST_OF_ALL_CREATED)
and see a list (array or object) of all promises. I not know the promise IDs or variable names.
我需要调试列表...例如,await
all,或一些选定的.
I need for debug list... And also for example, await
all, or some selected ones.
推荐答案
Promise.new()
的结果只是对承诺的引用.如果要列出应用程序中的所有承诺,则需要在创建它们时获得对它们的引用.
The result of Promise.new()
is just a reference to the promise. If you want to list all promises in an application, you need to get a reference to them when they're created.
Promise.all()
与获取应用程序中的所有活动承诺无关,它用于其他用途.
Promise.all()
is not related to getting all active promises in an application, it's used for something else.
没有什么神奇的方法可以获取应用程序中所有正在执行的"承诺的列表.您只需要获取变量引用,就像处理任何其他变量一样.
There is no magical way to get a list of all "in flight" promises in an application. You just need to get the variable references, the same way you would do for any other variable.
这篇关于如何列出所有承诺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!