1

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 (teams, 1000, fetchTeamInfo) ->
  async.parallelLimit arr.map((a, i) ->
    ->
      iterator a, i, arr
  ), limit

But not sure is it right way

Jesus_Maria
  • 1,137
  • 5
  • 14
  • 24

1 Answers1

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:

const fn = (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.

Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504