Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on Apr 27, 2024 via pnpm

async 3.2.5

Higher-order functions and common patterns for asynchronous code
Package summary
Share
0
issues
1
license
1
MIT
Package created
19 Dec 2010
Version published
3 Nov 2023
Maintainers
5
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
async@3.2.5
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of async 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does async do?

Async is a powerful utility module in JavaScript designed for working with asynchronous JavaScript. This tool provides straightforward functions that make it easier to manage and organize asynchronous code in JavaScript. It's particularly practical for use with Node.js but is also highly useful for coding directly in the browser. A version of Async, async-es, catered specifically for ESM is available as well.

How do you use async?

Async can be utilized using Node-style callbacks or ES2017 async functions. To use Async, you need to first install it with npm using the command npm i async. Once installed, you require it in your JavaScript file, as shown in the following examples:

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);
    doSomethingWith(configs);
});

In this snippet, the async.forEachOf function is used to iterate over each key-value pair in the obj object. It reads files and parses JSON data in an async way. If an error occurs, the callback function is called with the error. If no error occurs it does something with the configs.

Here is another example of how to use Async with ES2017 async functions:

var async = require("async");

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);
});

In this snippet, async.mapLimit function is used for applying the async function to each URL in the urls array. It does this with concurrency limit of 5, then logs out results or throws an error if one occurs.

Where are the async docs?

The official documentation for Async can be found at this URL: https://caolan.github.io/async/. This provides extensive detail on the many functions and features Async affords, as well as clear examples of how and when to use them.