How to list all promisses

2019-09-21 12:10发布

问题:

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.

I need for debug list... And also for example, await all, or some selected ones.

回答1:

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() 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.