Skip to content Skip to sidebar Skip to footer

Convert Async.eachlimit To Promise

I have such aync code async.eachLimit(teams, 1000, fetchTeamInfo, exit) I need to convert it to Promise (bluebird) I thought will be good to make something like: Promise.method (t

Solution 1:

Well, I see you're using Promise.method so I'm assuming bluebird - bluebird comes with Promise.map with already supports what you're looking for with the concurrency parameter:

constfn = (teams, concurrency) => Promise.map(teams, fetchTeamInfo, {concurrency});

As you see, we didn't really do here much - we can just use Promise.map directly :)

In CoffeeScript I think it'd look something like:

fn = (teams, concurrency) -> Promise.map teams, fetchTeamInfo, concurrency: concurrency

But I haven't written CoffeeScript in almost 3 years.

Post a Comment for "Convert Async.eachlimit To Promise"