node.js async libs

后端 未结 4 958
太阳男子
太阳男子 2020-12-07 17:33

There are a ton of libraries that help with fixing the layers of callback syndrome.

In fact, there\'s too many, which one do i use?

4条回答
  •  感动是毒
    2020-12-07 17:55

    I use Async.js.

    Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. Although originally designed for use with node.js, it can also be used directly in the browser.

    Examples

    async.map(['file1','file2','file3'], fs.stat, function(err, results){
        // results is now an array of stats for each file
    });
    
    async.filter(['file1','file2','file3'], path.exists, function(results){
        // results now equals an array of the existing files
    });
    
    async.parallel([
        function(){ ... },
        function(){ ... }
    ], callback);
    
    async.series([
        function(){ ... },
        function(){ ... }
    ]);
    

提交回复
热议问题