Is nodejs able to judge that all asynchrony is over?

  node.js, question

Because the program has too many asynchronous requests. Sometimes overtime or something, although it is still possible to tell when it will end, sometimes there are all sorts of small probabilities that are not accurate. That is to say, counting alone cannot accurately count all asynchrony is finished. Especially when the program business is very complicated.

If the judgment is not accurate, I cannot feed back to the user at all, and the program has been executed. Then the user has been waiting.

Therefore, it would be nice to be able to directly judge that all asynchrony on the page has ended. Do you have this?


I am currently using async/waterfall to implement, the code is as follows

function test(i){
 //Step 1
 function(callback) {
 thread(function (){
 //callback(null, 'a');
 }, 800);
 //Step 2
 function(a, callback){
 Dlog ('Proceed to Step 2' plus A);
 ], function (err, a, b) {
 Dlog ('End of Mission' plus A plus B);
 function thread(callBack, time){
 },  time)

As above, the normal flow: step 1-step 2-task end

When the task is finished, count+1. For example, when the total number of tasks = 10, count = 10 can judge that the task is all finished.

Now the question arises. If the one in step 1 is asynchronous, there is an exception and there is no callback. Can’t go to the next step, nature also can’t perform the end of the position.
The process was thus interrupted.

So the count is always less than 10. The task will never end.

As to why there is no callback. A series of operations, such as reading web pages and downloading pictures, have not set a timeout before. The asynchronous reading seems never to be recalled. Now there is no problem when setting a timeout.

Because the third-party module is used, there is still a probability that such problems will occur. As for why, it is estimated that one has to study the source code of others to find the answer.

An elegant method:

Use all asynchronous operationsPromisePackage. Then you canPromise.all(Escape