Brief introduction
the biggest feature of node. JS is the asynchronous I/O and event-driven architecture design. for highly concurrent solutions, the traditional architecture is a multithreaded model that provides a system thread for each business logic module to compensate for the time overhead of synchronous I/O calls through system thread switching. node. JS uses a single-threaded model, with asynchronous requests for all I/O, avoiding frequent context switching. node. JS maintains an event queue during execution, the program enters the event loop at execution time, waits for the next event to arrive, and each asynchronous I/O request is pushed to the event queue for processing by the program process.
Concept Synchronous Invocation
A synchronous call is a blocking call, and when a piece of code calls another code, it must wait for the code to finish executing and return the result before the code can continue to execute.
asynchronous invocation
An asynchronous call is a non-blocking call, and a piece of asynchronous code is not finished, and you can proceed to the next piece of code logic, and after the asynchronous code executes, return to the corresponding logic through the callback without delaying the execution of the other code.
Callback
Callbacks are not asynchronous calls, but callbacks are a way of handling the results of asynchronous function execution. At asynchronous invocation, if we want the results of asynchronous code execution to be returned and processed, it can be resolved by means of a callback. Note that the callback is also a blocking call.
Supplement: Asynchronous functions often do not return execution results directly, but instead return execution results to the callback function through event-driven methods, and then process the corresponding logical code in the callback function.
node. js asynchronous I/O and event-driven combat