- the setTimeout command - this command basically tells and scheduling a bit of code to run in 5 seconds. This command is usually instantaneous.
- console.log is a function mainly used to print a certain text, and usually can be linked to a specific function, if specified.
- you can also place functions in the process of another function, and run a bit of code
Simply think of this as a situation involving a waitress, a cook, and the customers. The customers are requesting for some data from the database, and the database basically represents the cook. The waitress will take the request, give it to the chef and individually do this to each customer. This would however, take a long period of time. Instead, using this type of code, including the setTimeout command, the waiter which practically represents the node.js code, will take all the requests simultaneously and then return the orders back from the database in a set period of time from the setTimeout command. Basically instead of taking one order at a time and waiting in between to return the order, it will instead take each request and give it to the chef to satisfy each request. This makes the code quicker and more efficient.
Note: This example is based of the example the tutorial gave.
No comments:
Post a Comment