Convert async.eachLimit to promise
I have aync code like this
async.eachLimit(teams, 1000, fetchTeamInfo, exit)
I need to convert it to Promise (bluebird)
I thought it would be good to do something like:
Promise.method (teams, 1000, fetchTeamInfo) ->
async.parallelLimit arr.map((a, i) ->
->
iterator a, i, arr
), limit
But not sure if this is the right way.
source to share
Well I see what you are using Promise.method
, so I assume bluebird - bluebird comes with Promise.map
already supporting what you are looking for with the concurrency parameter:
const fn = (teams, concurrency) => Promise.map(teams, fetchTeamInfo, {concurrency});
As you can see, we haven't done much here - we can just use Promise.map
directly :)
In CoffeeScript, I think it looks something like this:
fn = (teams, concurrency) -> Promise.map teams, fetchTeamInfo, concurrency: concurrency
But I haven't written CoffeeScript in almost 3 years.
source to share