@stackline/async
Higher-order functions and common patterns for asynchronous code.
Documentation | npm | Issues | Repository
Current package version: 1.0.2
Why this package?
@stackline/async is the Stackline-maintained distribution of async@3.2.6. It is an independent continuation of async; original authors and licenses remain credited below.
Compatibility
| Item | Value |
|---|---|
| Package | @stackline/async@1.0.2 |
| API target | async@3.2.6 |
| Supported Node.js | See supported framework requirements |
| License | MIT |
| Main entry | dist/async.js |
| Module entry | dist/async.mjs |
| Runtime dependencies | none |
Installation
npm install @stackline/async
Preserve existing imports and plugin resolution with an npm alias:
npm install async@npm:@stackline/async
Usage and API reference
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 @stackline/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("@stackline/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("@stackline/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)
})
Credits and original authors
- Original project: async.
- Caolan McMahon.
- Copyright (c) 2010-2018 Caolan McMahon.
- Stackline maintenance: Alexandro Paixao Marques and Stackline contributors.
Original copyright, license notices and contributor acknowledgements remain part of this distribution. Stackline maintenance does not replace authorship of the original work.
License
MIT. See the license and notice files in the repository.
Community and Links
Use this repository's issue tracker for reproducible bugs and feature requests. Join r/Stackline for examples, usage questions and release discussions.