Nodejs simple getting started tutorial (2): timer, nodejs simple
SetTimeout and clearTimeout
Copy codeThe Code is as follows:
Var obj = setTimeout (cb, MS );
SetTimeout is used to set a callback function cb that is executed after a minimum MS of milliseconds (not immediately after a MS of milliseconds ). The setTimeout return value can be used as the clearTimeout parameter. clearTimeout is used to stop the timer, so that the callback function will not be executed.
SetInterval and clearInterval
Copy codeThe Code is as follows:
Var obj = setInterval (cb, MS );
SetInterval is similar to setTimeout, but setInterval executes cb once every MS Millisecond (not exactly after MS milliseconds. The setInterval return value can be used as the clearInterval parameter. clearInterval is used to stop the timer, so that the callback function will not be executed.
SetImmediate and clearImmediate
Copy codeThe Code is as follows:
Var obj = setImmediate (cb );
SetImmediate is used to call the cb function in a delayed manner. Cb is called after I/O Event Callback and before setTimeout and setInterval callback. The return value of setImmediate can be used as the clearImmediate parameter. clearImmediate is used to stop triggering the callback function.
Process. nextTick
Copy codeThe Code is as follows:
Process. nextTick (cb );
Similar to the setImmediate function, this function is used to call the cb function in a delayed manner. Cb will be called before I/O Event Callback (unlike setImmediate ). Process. nextTick is much more efficient than setTimeout (cb, 0. Process. nextTick can execute a maximum of process. maxTickDepth callback functions in each loop, while setImmediate only executes One callback function in each loop.
How can I get started with nodejs from scratch?
It's very simple from scratch! This MOOC is free for you to learn. As long as you have a little javascript knowledge, you can easily make nodejs examples. In fact, the JSP code is quite simple, and anyone with programming experience can understand it, it is not difficult to generate JSON or Javascript arrays.
Q: Is it easy to learn about the classic nodejs tutorials?
This MOOC can start from scratch without spending money, that is, it is easy to learn nodejs directly without learning anything else, and it is not linked to other knowledge, you can start from scratch.