Skip to content

caolan/async

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date
Oct 21, 2024
Aug 19, 2024
Aug 19, 2024
Aug 8, 2024
Jun 29, 2016
Dec 2, 2021
Dec 9, 2021
Nov 3, 2023
Aug 5, 2018
Jan 16, 2016
Jan 28, 2022
Nov 3, 2023
Jun 2, 2016
May 27, 2019
Jun 29, 2016
Nov 6, 2023
Jan 20, 2018
Jun 23, 2019
Jan 28, 2022
Jan 2, 2024
Jun 3, 2018
Feb 10, 2016
Aug 5, 2021
Jan 28, 2022
Oct 2, 2024
Sep 2, 2024

Repository files navigation

Async Logo

Github Actions CI status 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 i async, it can also be used directly in the browser. An ESM/MJS 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)
})