Is a call to Node.js' async.parallel() synchronous?

后端 未结 3 1324
野的像风
野的像风 2020-12-20 06:40

I am taking a look at Node.js\' async module to solve an issue. I have implemented a little test:

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

function prin         


        
3条回答
  •  太阳男子
    2020-12-20 07:15

    Can I be sure that the Trulu log call will never be called before the call to async.parallel is finished?

    The call itself, yes.

    In other words, are all the functions

    I guess so, though the docs don't mention it. I would however expect no changes, since that is likely to break existing code.

    and the final callback called before the Trulu log is called for sure?

    No. You don't know the functions, and when they are asynchronous then the final callback will execute after Trulu. If all the functions are synchronous, you shouldn't use async anyway. Indeed, while async.js does use setImmediate internally so some callbacks (unfortunately hard to identify) will be "asynchronified", yet the maintainer stated:

    Yes, making functions asynchronous is left up to the developer

    If you want to ensure that callbacks are always called asynchronously (after Trulu), even when the functions are synchronous, you might consider using A+ compliant Promises.

提交回复
热议问题