peachy
v1.0.3
Published
a tiny (23 lines of code) parallel async each/map module
Downloads
2
Maintainers
Readme
peachy
A tiny (23 lines of code) parallel async each/map implementation that supports CommonJS, AMD, and VanillaJS. The minified file peachy.min.js
is just 360 bytes.
Install
npm
npm install peachy
bower
bower install peachy
Usage
parallelEach(array, iterator, callback)
Arguments
array
- An array to iterate overiterator(item, callback, index)
- A function called for eachitem
in thearray
. Thecallback(err, value)
optionally takes an error or data. Data is collected and provided when all iterator functions have finished. Theindex
value is the index of the item in the array.callback(err, values)
- The callback that is called when alliterator
functions are finished or an error occurs. Thevalues
argument is an array of values collected from iterator functions. The index of the value in values maps to the index of the item provided to the iterator function.
Examples
Browser (No module loader)
<script src="/js/peachy.min.js"></script>
<script>
// parallelEach is a global bound to the window object now
parallelEach(['hi', 'i love', 'alerts'], function(word, done) {
alert(word);
done();
});
</script>
Node.js
var parallelEach = require('peachy');
var fs = require('fs');
parallelEach(['robots.txt', 'todo.txt'], fs.readFile, function(err, files) {
files.forEach(function(text) {
console.log(text);
});
console.log('You should have all the information you need now.');
});