Nodejs Basic (5-6) HTTP concept Advanced

Source: Internet
Author: User

1. What is a callback? Is the most basic method of asynchronous programming, in order to nodejs the need to execute asynchronous logic in the time of the general use of subsequent delivery, that is, the subsequent logic encapsulated in the callback function as the starting function of the parameters are nested by layer. This way, the program goes through the process in the way that we expect.

2. What is synchronous/asynchronous? Synchronization is the execution of a task, and the latter task waits until the previous task finishes executing. The order in which the programs are executed is consistent with the order in which the tasks are arranged. JS in the browser is single-threaded, executed sequentially, although the JS file can be downloaded in parallel, but must be executed sequentially. If there is a dead loop in JS, then the page will be blocked here, the subsequent JS will not be executed.

The asynchronous function in JS: SetTimeOut setinterval

1 varc =02 3 function PrintIt () {4 Console.log (c)5 }6 function Plus (callback) {7 setTimeout (function () {8c+=19 Callback ()Ten}, +) One } A  -Plus (PrintIt)

3. What is I/O? Disk write and read out, data in and out. In Nodejs, it is essentially a database and file system for these resources to provide interfaces, send a request to the file system without waiting for the hard disk, when the hard disk is ready, the non-blocking interface will notify node.

4. What is single thread/multithreading? Single thread: programs are executed sequentially. Can only talk about one girlfriend at a time, after breaking up the next. If a girlfriend haunts you, it can cause obstruction.

Multithreading: It is difficult to manage and allocate resources. You can pedal a few boats at the same time, but allocate resources. Otherwise the scramble for resources, oneself will collapse.

5. What is blocking/non-blocking? Blocking: If you call to make an appointment, if the other party does not reply, he has been suspended here. Non-blocking: Wait for the reply, oneself will go to play first, can call to ask every time.

6. What is an event? Mouse click, drag window and so on.

7. What is event driven? All events that are triggered are instances of eventemitter. A callback function is registered for an event, and the callback function is not executed immediately, and the callback function is invoked only when the event occurs, and this function is called event-driven. This callback is called an event-driven callback. If these callbacks are related to asynchronous IO operations, this can be thought of as callback-based asynchronous Io, which is driven by events in the Nodejs.

8. What is an event-driven callback?

9, what is the event loop EventLoop? If there is a large number of asynchronous operations, as well as the time-consuming operation of IO or even timer-controlled delay operation, they will call the corresponding callback function to complete some intensive tasks without blocking the entire program execution process, so many events need to have a mechanism to manage, this mechanism is the event loop.

EventLoop: is a callback function queue. When the asynchronous function executes, the callback function is pressed into the queue, and for Nodejs a single thread keeps querying the queue for events, and when he reads an event, it invokes the JS function associated with the event. The loop of an event is a first-in-one task queue. Callbacks are executed in the order in which they are added to the queue. The entire queue can be understood as a complete queue of normal functions and callback functions.

Nodejs's core idea: single-threaded non-blocking and event-driven

Nodejs Basic (5-6) HTTP concept Advanced

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.