index.js 269 B

123456789101112131415161718192021
  1. /**
  2. * Expose `thread`.
  3. */
  4. module.exports = thread;
  5. /**
  6. * Run `fn` `n` times in parallel.
  7. *
  8. * @param {Function} fn
  9. * @param {Number} n
  10. * @return {Array}
  11. * @api public
  12. */
  13. function thread(fn, n) {
  14. var gens = [];
  15. while (n--) gens.push(fn);
  16. return gens;
  17. }