Async

Async utilities for node and the browser

README

Async Logo

Github Actions CI status NPM version Coverage Status Join the chat at https://gitter.im/caolan/async jsDelivr Hits

<!--
|Linux|Windows|MacOS|
|-|-|-|
|[![Linux

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 vianpm i async, it can also be used directly in the browser.  A 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](https://www.npmjs.com/package/async-es).

For Documentation, visit

For Async v1.5.x documentation, go HERE


  1. ``` js
  2. // for use with Node-style callbacks...
  3. var async = require("async");

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

  6. async.forEachOf(obj, (value, key, callback) => {
  7.     fs.readFile(__dirname + value, "utf8", (err, data) => {
  8.         if (err) return callback(err);
  9.         try {
  10.             configs[key] = JSON.parse(data);
  11.         } catch (e) {
  12.             return callback(e);
  13.         }
  14.         callback();
  15.     });
  16. }, err => {
  17.     if (err) console.error(err.message);
  18.     // configs is now a map of JSON data
  19.     doSomethingWith(configs);
  20. });
  21. ```

  1. ``` js
  2. var async = require("async");

  3. // ...or ES2017 async functions
  4. async.mapLimit(urls, 5, async function(url) {
  5.     const response = await fetch(url)
  6.     return response.body
  7. }, (err, results) => {
  8.     if (err) throw err
  9.     // results is now an array of the response bodies
  10.     console.log(results)
  11. })
  12. ```