UNPKG

1.15 kBMarkdownView Raw
1# async-each
2
3No-bullshit, ultra-simple, 40-lines-of-code async parallel forEach function for JavaScript.
4
5We don't need junky 30K async libs. Really.
6
7For browsers and node.js.
8
9## Usage
10
11`npm install async-each` if you're using NPM.
12
13For browsers, just include async-each before your scripts and use global variable `asyncEach`
14
15* `each(array, iterator, callback)``Array`, `Function`, `(optional) Function`
16* `iterator(item, next)` receives current item and a callback that will mark the item as done. `next` callback receives optional `error, transformedItem` arguments.
17* `callback(error, transformedArray)` optionally receives first error and transformed result `Array`.
18
19```javascript
20var each = require('async-each');
21each(['a.js', 'b.js', 'c.js'], fs.readFile, function(error, contents) {
22 if (error) console.error(error);
23 console.log('Contents for a, b and c:', contents);
24});
25
26asyncEach(list, fn, callback); // use global var in browser
27```
28
29## License
30
31The MIT License (MIT)
32
33Copyright (c) 2016 Paul Miller [(paulmillr.com)](https://paulmillr.com)
34
35See [LICENSE](https://github.com/paulmillr/async-each/blob/master/LICENSE) file.