The difference between Setimmediate vs. Nexttick

Source: Internet
Author: User

Reference: Http://stackoverflow.com/questions/15349733/setimmediate-vs-nexttick

Setimmediate occurs after an I/O event has been triggered on the event queue, Process.nexttick before the event queue, and occurs after the current function has ended.

So, if you're going to interrupt a long run, using a recursive CPU task, you can use setimmediate instead of Process.nexttick to insert the next iteration, otherwise any I/O event callbacks will not have any chance of being invoked during the iteration.

Other than that:


The callback function passed to Process.nexttick is usually called at the end of the execution event stream, so it is best for synchronization operations as fast as possible. If no check is made, this consumes the event loop and prevents I/O from occurring. Setimmediates inserts the queue in the order in which it was created, and pops up during each iteration. This is very different from Process.nexttick, where Process.nexttick executes the process.maxtickdepth queue callback function at each iteration. Setimmediate will yield to the event loop after triggering the queue callback function to ensure that I/O is not consumed.

The difference between Setimmediate vs. Nexttick

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.