将async.eachLimit转换为promise [英] convert async.eachLimit to promise

查看:115
本文介绍了将async.eachLimit转换为promise的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的异步代码

async.eachLimit(teams,1000,fetchTeamInfo,exit)

我需要将其转换为Promise(蓝鸟)

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

但不确定方法是否正确

推荐答案

好吧,我看到您使用的是 Promise.method ,所以我假设bluebird-bluebird随附了 Promise.map 已通过并发参数支持您要查找的内容:

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});

如您所见,我们在这里并没有做太多工作-我们可以使用 Promise.map 直接:)

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

在CoffeeScript中,我认为它类似于:

In CoffeeScript I think it'd look something like:

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

但是我已经有将近三年没有写CoffeeScript了。

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

这篇关于将async.eachLimit转换为promise的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆