node. js Api--timers (timer)

Source: Internet
Author: User

//Descriptionthe Node API version is v0.10.31.
Chinese Reference: http://nodeapi.ucdok.com/#/api/this Keweibo main note.
Directory Timer
0 SetTimeout (callback, delay, [ARG], [...])
0 cleartimeout (timeoutobject)
0 SetInterval (callback, delay, [ARG], [...])
0 clearinterval (intervalobject)
0 unref ()
0 ref ()
0 Setimmediate (callback, [Arg], [...])
0 clearimmediate (immediateobject)
Stability: 5-locked
all of the timer functions are global. You do not need to require () this module in order to use them. SetTimeout (callback, delay, [ARG], [...])a callbackis scheduled to execute after delay milliseconds. Returns a timeoutobject for cleartimeout () to use when needed. Optionally, you can also pass parameters to the callback function. It is important to note that your callback function is probably not called after the exact delay millisecond--node.js does not guarantee the exact timing of the callback function execution and the order of execution. The callback function is only executed as close as possible to the specified time. Cleartimeout (Timeoutobject)prevents a timeout timer from triggering. SetInterval (callback, delay, [ARG], [...])Schedule callbackto repeat after every delay millisecond. Returns a intervalobject for clearinterval () to use when needed. Optionally, you can also pass parameters to the callback function. Clearinterval (Intervalobject)stops the triggering of a interval timer. Unref ()the opaque values returned by setTimeout and setinterval also have the timer.unref () method, which allows you to create an active timer, However, if it is the only remaining item in the event loop, the program will not be kept running. If the timer has been unref, calling unref again will have no effect. in the case of setTimeout , when you unref will create another timer that will wake up the event loop. Creating too many of these timers can have an adverse effect on the performance of the event loop-use caution. Ref ()If you have previously unref () a timer, you can call ref () to explicitly require the timer to keep the program running. If the timer has already been ref, calling ref again will have no effect. Setimmediate (callback, [Arg], [...])after I/O event callbacks are scheduled, the callbackis executed "immediately" beforesetTimeout and setinterval . Returns a immediateobject for clearimmediate () to use when needed. Optionally, you can pass parameters to the callback function. The immediate events are placed in the queue in the order in which they were created, and one pops up from the queue header in each iteration of the event loop. This is different from Process.nexttick , which executes the callback function in the process.maxtickdepth queue in each iteration. Setimmediate executes a callback function in a queue and discards (consumes the CPU) back to the event loop to ensure I/O is not impossible to initiate. When the order of execution is saved, other I/O events may be executed between any two scheduled immediate callback functions. Clearimmediate (Immediateobject)stop a immediate timer trigger.

node. js Api--timers (timer)

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.