node.js 异步库 [英] node.js async libs

查看:34
本文介绍了node.js 异步库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有大量的库可以帮助修复回调综合症层.

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?

推荐答案

我使用 Async.js.

Async 是一个实用模块,它提供直接、强大的用于工作的函数异步 JavaScript.虽然最初设计用于node.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.

示例

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(){ ... }
]);

这篇关于node.js 异步库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆