https://github.com/semibran/async-map
Transform each value in an array asynchronously
https://github.com/semibran/async-map
async map
Last synced: about 1 year ago
JSON representation
Transform each value in an array asynchronously
- Host: GitHub
- URL: https://github.com/semibran/async-map
- Owner: semibran
- License: mit
- Created: 2017-06-05T04:01:59.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-03-18T19:06:09.000Z (over 8 years ago)
- Last Synced: 2025-03-13T19:50:51.090Z (over 1 year ago)
- Topics: async, map
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# async-map
> transform multiple values asynchronously in parallel
## install
[![npm badge]][npm package]
```sh
npm install async-map
```
## usage
```js
const asyncMap = require('async-map')
const loadImage = require('img-load')
let paths = ['images/foo.png', 'images/bar.png']
asyncMap(paths, loadImage, (err, images) => {
if (err) throw err
for (let image of images) {
document.body.appendChild(image)
}
})
```
### `asyncMap(values, iterator, callback)`
Performs `iterator` on each value in `values` in parallel, and passes the result into `callback` when complete.
* `values`: An array of values to be transformed
* `iterator(value, callback)`: Any function that receives a value and a callback, e.g. [`fs.stat(path, callback)`](https://nodejs.org/api/fs.html#fs_fs_stat_path_callback)
* `callback(err, result)`: The function called upon completion or abortion of the mapping process
[npm package]: https://www.npmjs.org/package/async-map
[npm badge]: https://nodei.co/npm/async-map.png?mini