how do i create a non-blocking asynchronous function in node.js?

前端 未结 10 960
悲&欢浪女
悲&欢浪女 2020-12-02 13:27

How do I create a non-blocking asynchronous function? Below is what I\'m trying to achieve but my program is still blocking...

var sys = require(\"sys\");

f         


        
10条回答
  •  死守一世寂寞
    2020-12-02 14:10

    If i do understand what you're after, you have two functions (both take a callback as argument):

    process.nextTick: this function can be stacked, meaning that if it is called recursively, it will loop a huge (process.maxTickDepth) number of times per tick of the event loop.

    or

    setImmediate: this function is much closer to setting a 0 timeout (but happens before).

    In most cases, you should prefer setImmediate.

提交回复
热议问题