Async+await's preliminary understanding of the execution process of the synchronous/asynchronous sending interface

The rookie's personal record is just a simple understanding, without involving the basic principles, to be updated

This seems to be closely related to promise, so I still need to understand it better

1. First of all, the default execution order of the interface is [asynchronous].

2. Then know that async is a decoration mark for functions, and await is the method to make the execution of the interface [from asynchronous to synchronous]

3. When we want to use the interface to obtain data, if we do not add await, it will be in an asynchronous state.

        

        Checking the interface and printing results, we found that the interface has been sent at this time, but we did not get the data at the front end, and the Promise shows that it is in the pending (in progress) state, which is asynchronous and needs to wait for other executions to return (I don’t know about the esoteric knowledge here, but I just know that this is probably the case)

 

 4. When we use await, the execution of the interface becomes synchronous

         We can find that when we send out the interface, we can get the data immediately without waiting. This is synchronization

 5. If you don't use await, you can also use .then to execute

Important: When executing with await, subsequent statements cannot be executed due to an interface error. At this time, try catch can be used to solve the problem

Guess you like

Origin blog.csdn.net/gjylalaland/article/details/127283420
Recommended