1
|
# async-each
|
2
|
|
3
|
No-bullshit, ultra-simple, 35-lines-of-code async parallel forEach function for JavaScript.
|
4
|
|
5
|
We don't need junky 30K async libs. Really.
|
6
|
|
7
|
For browsers and node.js.
|
8
|
|
9
|
## Installation
|
10
|
* Just include async-each before your scripts.
|
11
|
* `npm install async-each` if you’re using node.js.
|
12
|
|
13
|
## Usage
|
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
|
20
|
var each = require('async-each');
|
21
|
each(['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
|
|
26
|
// Alternatively in browser:
|
27
|
asyncEach(list, fn, callback);
|
28
|
```
|
29
|
|
30
|
## License
|
31
|
|
32
|
The MIT License (MIT)
|
33
|
|
34
|
Copyright (c) 2016 Paul Miller [(paulmillr.com)](http://paulmillr.com)
|
35
|
|
36
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
37
|
of this software and associated documentation files (the “Software”), to deal
|
38
|
in the Software without restriction, including without limitation the rights
|
39
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
40
|
copies of the Software, and to permit persons to whom the Software is
|
41
|
furnished to do so, subject to the following conditions:
|
42
|
|
43
|
The above copyright notice and this permission notice shall be included in
|
44
|
all copies or substantial portions of the Software.
|
45
|
|
46
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
47
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
48
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
49
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
50
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
51
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
52
|
THE SOFTWARE.
|