Promise.all在babel ES6实施中解决 [英] Promise.allSettled in babel ES6 implementation

查看:327
本文介绍了Promise.all在babel ES6实施中解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用babel转换我的node.js@0.10.x代码,但我信守诺言.

I'm using babel to transpile my node.js@0.10.x code and I'm stuck with promises.

我需要例如可以在qbluebirdangular.$q中使用的allSettled类型功能.

I need allSettled-type functionality that I could use in q and bluebird or angular.$q for example.

在babel的core-js Promise上,没有allSettled方法.

On babel's core-js Promise, there is no allSettled method.

当前,我正在使用q.allSettled作为解决方法:

Currently I'm using q.allSettled as a workaround:

import { allSettled } from 'q';

babel polyfill中有类似的东西吗?或者,这是我尝试实施的一种很好的算法?

Is there something like that in babel polyfill? Alternatively, which is a good algorithm for me to try to implement?

推荐答案

或者,这是我尝试实现的一种很好的算法?

Alternatively, which is a good algorithm for me to try to implement?

  1. 使用执行程序功能创建新的承诺
  2. 在执行程序的范围内使用计数器/结果数组
  3. 向每个父对象注册一个then()回调,并将结果保存在数组中
  4. 当计数器指示所有父项承诺均已完成时,从步骤1解析/拒绝承诺
  1. create a new promise with an executor function
  2. use a counter/result array in the scope of the executor
  3. register a then() callback with each parent promise saving the results in the array
  4. resolve/reject promise from step 1 when counter indicates that all parent promises are done

这篇关于Promise.all在babel ES6实施中解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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