Third, the "Secret Internet companies first-line front-end Advanced JavaScript Interview" video tutorial series three summary: js asynchronous related

 


 

Series catalog: https://www.cnblogs.com/lmyxywy/p/10931603.html

 


 

The question: What is a single-threaded? And asynchronous What is the connection?

 

Single thread is only one thing at the same time, two js can not be performed simultaneously.

This is because Dom js can operate, in order to avoid a two js also modify the elements of Dom collision occurs, it js the authors used single-threaded mechanism.

In addition, because the UI rendering browser needs to render Dom elements, so in order to avoid conflict and js, js UI rendering and also in the same thread inside;

Which js modify Dom time, UI rendering needs to be suspended.

Both are single-threaded essence of the conflict in order to avoid rendering Dom.

 

According to the principle of single-threaded, did not finish one thing before the program will not go down, so will inevitably lead to wait and wait for a long time more often it will cause obstruction.

An asynchronous single-threaded blocking problems is to solve the "helpless" solution.

Asynchronous principle: popular terms, is experiencing an event to wait, skip the first, continue to go down synchronized event, when the time arrives to handle asynchronous events until, go back to asynchronous events.

 

 Asynchronous problems caused by:

1, is not executed in accordance with the written order, readability is very poor, is not conducive to the understanding and debugging;

2, callback (the callback function) is nested multi-level, high degree of coupling, modularity is not easy.

 


 

Question two: What is event-loop? What is asynchronous queue, when it was put into an asynchronous queue?

 

event-loop event polling, JS asynchronous specific solutions.

 

event-loop execution principles:

1, all synchronization tasks are placed in the main process execution, execution form a stack;

2, met asynchronous tasks, they will not perform the task into an asynchronous queue, it is outside the main process asynchronous tasks specialized storage queue ;

        The timing of asynchronous queue into three cases:

        ① predetermined delay time is not immediately placed in the asynchronous queue;

        ② delay time, the delay time is then put to the asynchronous queue;

        ③ Similarly Ajax, need to wait for the returned data, when the data is received when the asynchronous queue into.

3, the main process is finished until all synchronization tasks, monitor asynchronous queues, polling perform asynchronous tasks.

(Polling is: as long as the main course was empty, the queue of asynchronous task will enter the execution stack, waiting for execution stack is finished, the system again asynchronous queue monitor reading task, let into the asynchronous task execution stack, ad infinitum)

 


 

Work, and to be continued. . .

 

Question three: if used the Jquery Deferred?

Question four: Basic principles and use of Promise.

Question 5: introduce the async / await (and the differences and connections of Promise)

 

Guess you like

Origin www.cnblogs.com/lmyxywy/p/11308862.html