async-q icon indicating copy to clipboard operation
async-q copied to clipboard

Might consider using _.map instead of arr.map

Open mmiller42 opened this issue 8 years ago • 3 comments

The original async library allows iterating over "collections" instead of just arrays, i.e. it also iterates over hasOwnProperties of objects. By using Lodash's map method, this could be supported with async-q with minimal code changes.

mmiller42 avatar May 12 '16 21:05 mmiller42

just encountered this - would be nice to be able to use an iterator

i created a generator to iterate over more elements than could sanely be put into memory at once

kumavis avatar May 08 '18 05:05 kumavis

just checked, seems lodash.map does not handle iterators correctly https://github.com/lodash/lodash/issues/3780

kumavis avatar May 08 '18 05:05 kumavis

ok I realize that iterator support may be out of scope of just "collections" support, sorry to piggy back on this issue. For future github travelers, I solved it this way.

const PromisePool = require('es6-promise-pool')

async function eachLimit(iterator, asyncFn, concurrency) {
  const pool = new PromisePool(() => {
    const next = iterator.next()
    if (next.done) return null
    return asyncFn(next.value)
  }, concurrency)
  return pool.start()
}

kumavis avatar May 08 '18 06:05 kumavis