当前位置:网站首页>JS手写实现Promise.all
JS手写实现Promise.all
2022-08-09 14:54:00 【好帅的爸爸()】
function promiseAll(promises) {
// 保存所有结果
let result = [];
// 统计是否全部执行完毕
let count = 0;
return new Promise((resolve, reject) => {
for(let i = 0; i < promises.length; i++) {
count++;
promises[i].then(function(value) {
// 下表位置添加结果
result[i] = value;
// 全部完成后resolve
if(count === promises.length) {
resolve(result);
}
}).catch(function(reason) {
// 失败直接推出.
reject(reason);
})
}
})
}边栏推荐
猜你喜欢

stream去重相同属性对象

Mathematica 作图详解

What is a template engine?What are the common template engines?Introduction to common commands of thymeleaf.

ASP.Net Core实战——初识.NetCore

.Net Core 技巧小结

光线的数值追踪

ASP.Net Core实战——使用Swagger
深刻地认识到,编译器会导致编译结果的不同
![[MySql] implement multi-table query - one-to-one, one-to-many](/img/7e/8f1af4422a394969b28a553ead2c42.png)
[MySql] implement multi-table query - one-to-one, one-to-many

Qt control - QTextEdit usage record
随机推荐
如何让你的量化交易系统具有概率优势,具有正向收益预期呢?
对导入的 excel 的时间的处理 将excel表中的时间,转成 标准的时间
.Net Core 技巧小结
常见的数学物理方程
WebGL:BabylonJS入门——初探:数据展示
突然想分析下房贷利率及利息计算
Analysis of the common methods and scopes of the three servlet containers
对程序化交易系统接口有什么误区?
双摄像头系列原理深度剖析【转载】
相干光(光学)
量子力学初步
一些需要思考的物理问题
How to achieve stable profit through the stock quantitative trading interface?
Arduino 飞鼠 空中鼠标 陀螺仪体感鼠标
文件操作的实例——下载并合并流式视频文件
如何保证电脑硬盘格式化后数据不能被恢复?
[Mysql]--事务、事务的隔离级别、脏读、不可重复读、幻读解析
二叉排序树的左旋与右旋
[MySql] implement multi-table query - one-to-one, one-to-many
走得通,看得见!你的交通“好帮手”