How to judge the end of both asynchrony and then execute the third function synchronously

  node.js, question


 url: "test1.html",
 url: "test2.html",
 function foo(){
 Log ('both ajax requests ended');

How to execute foo () after two ajax events are executed asynchronously and both are completed

In node.js, if you want to send two requests and obtain the data of the two requests before you perform a series of operations, what method should you use?

Promise method:
If you need two to execute in turn, you can connect them with then. If you have no requirement for order, you can put them into an array and execute them with Promise.all.

Callback method:
If it needs to be executed in sequence, the latter asynchronous callback function can be written to the former asynchronous callback function inside, and the third function can be written to the latter asynchronous callback function inside, thus forming the so-called’ callback hell’ …
If simultaneous execution is required, a counter, such as count, can be written with an initial value of 0. In both asynchronous callback functions, inside performs count plus, and then judges that if count is 2, that is, both are finished, the third function is executed.