websocket快速操作工具
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.

35 lines
1.1 KiB

  1. # async-each
  2. No-bullshit, ultra-simple, 40-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. ## Usage
  6. `npm install async-each` if you're using NPM.
  7. For browsers, just include async-each before your scripts and use global variable `asyncEach`
  8. * `each(array, iterator, callback)``Array`, `Function`, `(optional) Function`
  9. * `iterator(item, next)` receives current item and a callback that will mark the item as done. `next` callback receives optional `error, transformedItem` arguments.
  10. * `callback(error, transformedArray)` optionally receives first error and transformed result `Array`.
  11. ```javascript
  12. var each = require('async-each');
  13. each(['a.js', 'b.js', 'c.js'], fs.readFile, function(error, contents) {
  14. if (error) console.error(error);
  15. console.log('Contents for a, b and c:', contents);
  16. });
  17. asyncEach(list, fn, callback); // use global var in browser
  18. ```
  19. ## License
  20. The MIT License (MIT)
  21. Copyright (c) 2016 Paul Miller [(paulmillr.com)](https://paulmillr.com)
  22. See [LICENSE](https://github.com/paulmillr/async-each/blob/master/LICENSE) file.