Nodejs simple getting started tutorial (2): timer, nodejs simple

Source: Internet
Author: User

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.

Related Article

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.