You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
2.0 KiB

4 years ago
  1. # async-each
  2. No-bullshit, ultra-simple, 35-lines-of-code async parallel forEach function for JavaScript.
  3. We don't need junky 30K async libs. Really.
  4. For browsers and node.js.
  5. ## Installation
  6. * Just include async-each before your scripts.
  7. * `npm install async-each` if you’re using node.js.
  8. ## Usage
  9. * `each(array, iterator, callback);``Array`, `Function`, `(optional) Function`
  10. * `iterator(item, next)` receives current item and a callback that will mark the item as done. `next` callback receives optional `error, transformedItem` arguments.
  11. * `callback(error, transformedArray)` optionally receives first error and transformed result `Array`.
  12. ```javascript
  13. var each = require('async-each');
  14. each(['a.js', 'b.js', 'c.js'], fs.readFile, function(error, contents) {
  15. if (error) console.error(error);
  16. console.log('Contents for a, b and c:', contents);
  17. });
  18. // Alternatively in browser:
  19. asyncEach(list, fn, callback);
  20. ```
  21. ## License
  22. The MIT License (MIT)
  23. Copyright (c) 2016 Paul Miller [(paulmillr.com)](http://paulmillr.com)
  24. Permission is hereby granted, free of charge, to any person obtaining a copy
  25. of this software and associated documentation files (the “Software”), to deal
  26. in the Software without restriction, including without limitation the rights
  27. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  28. copies of the Software, and to permit persons to whom the Software is
  29. furnished to do so, subject to the following conditions:
  30. The above copyright notice and this permission notice shall be included in
  31. all copies or substantial portions of the Software.
  32. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  33. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  34. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  35. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  36. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  37. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  38. THE SOFTWARE.