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

查看:101
本文介绍了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

异步是一种实用工具模块,
  提供直接的,功能强大
  对于工作职能
  异步的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天全站免登陆