Async

Async 是一个实用程序模块,它为使用异步JavaScript提供了直观、强大的功能。(Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. )

Github stars Tracking Chart

Async 是一个实用程序模块,它为使用异步JavaScript提供了直观,强大的功能。 虽然最初设计用于Node.js并可通过 npm install --save 异步安装,但它也可以直接在浏览器中使用。

Async 也可以通过以下方式安装:
  • yarn:yarn add async
  • bower:bower install async

Async 提供了大约70个函数,包括通常的“functional”嫌疑人(map, reduce, filter, each...)以及异步控制流(parallel, series, waterfall...)的一些常见模式。 所有这些功能都假定您遵循提供单个回调的Node.js约定作为异步函数的最后一个参数 - 这是一个回调,该回调期望Error作为其第一个参数,并调用回调一次。

Overview

Name With Ownercaolan/async
Primary LanguageJavaScript
Program languageMakefile (Language Count: 4)
Platform
License:MIT License
Release Count87
Last Release Namev3.2.5 (Posted on 2023-11-03 15:10:27)
First Release Namev0.1.0 (Posted on )
Created At2010-06-01 21:01:30
Pushed At2024-04-01 22:05:19
Last Commit At2024-04-01 15:05:13
Stargazers Count28.1k
Watchers Count661
Fork Count2.4k
Commits Count1.9k
Has Issues Enabled
Issues Count1122
Issue Open Count7
Pull Requests Count516
Pull Requests Open Count0
Pull Requests Close Count310
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Async Logo

Build Status via Travis CI
Build Status via Azure Pipelines
NPM version
Coverage Status
Join the chat at https://gitter.im/caolan/async
jsDelivr Hits

Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. Although originally designed for use with Node.js and installable via npm install async, it can also be used directly in the browser. A ESM version is included in the main async package that should automatically be used with compatible bundlers such as Webpack and Rollup.

A pure ESM version of Async is available as async-es.

For Documentation, visit https://caolan.github.io/async/

For Async v1.5.x documentation, go HERE

// for use with Node-style callbacks...
var async = require("async");

var obj = {dev: "/dev.json", test: "/test.json", prod: "/prod.json"};
var configs = {};

async.forEachOf(obj, (value, key, callback) => {
    fs.readFile(__dirname + value, "utf8", (err, data) => {
        if (err) return callback(err);
        try {
            configs[key] = JSON.parse(data);
        } catch (e) {
            return callback(e);
        }
        callback();
    });
}, err => {
    if (err) console.error(err.message);
    // configs is now a map of JSON data
    doSomethingWith(configs);
});
var async = require("async");

// ...or ES2017 async functions
async.mapLimit(urls, 5, async function(url) {
    const response = await fetch(url)
    return response.body
}, (err, results) => {
    if (err) throw err
    // results is now an array of the response bodies
    console.log(results)
})
To the top