1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
1 2 3 4 5 |
|
Some basic concepts in JS
The callback is a function that encapsulates the subsequent logic into the parameters of the starting function and nests it layer by layer.
Synchronous: After sending data, wait for a response before sending the next data packet.
Asynchronous: after sending data, waitResponse, then send the next data packet communication method
In the file system:
1 2 |
|
One timecan only executeOneprogram is calledsingle-threaded
One timecan Executing multiple programs is called multithreading
Blocking: You have to wait until the previous program has been executed
Non-blocking:When the previous program has not been executed You can suspend, continue to execute other programs, and then execute it when it is used
A triggered action (such as clicking a button)
An operation caused by a trigger action (for example, a dialog box pops up after clicking a button)
A callback function is registered for a certain event, but this callback function is not executed immediately ,
will only be called when the event occurs Function, the way this function is executed is called Event-driven.
This kind of registered callback is based on event-driven callback.
If these callbacks are related to asynchronous I/O (data writing, reading) operations, they can be regarded as asynchronous I/O based on callbacks.
It’s just that this kind of callback is driven by events in nodejs
Event loop Eventloop, if there are a large number of asynchronous operations, such as some I/O time-consuming operations, or even some timer-controlled delayed operations,
they are completed The corresponding callback function must be called at all times to complete some intensive tasks without blocking the entire program execution process. At this time, a mechanism is needed to manage, which is called an event loop
In summary, the mechanism for managing a large number of asynchronous operations is called an event loop.
The above is the detailed content of Node.JS related knowledge. For more information, please follow other related articles on the PHP Chinese website!