当前位置:网站首页>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);
})
}
})
}
边栏推荐
- [Elementary C language] Detailed explanation of branch statements
- 用户如何正确去认识程序化交易?
- 抢占量化交易基金产品先机,量化投资有发展空间?
- A shortcut method for writing menu commands in C
- C#轻量级ORM使用 Dapper+Contrib
- WebGL探索——抉择:实践方向(twgl.js、Filament、Claygl、BabylonJS、ThreeJS、LayaboxJS、SceneJS、ThinkJS、ThingJS)
- Sort method (Hill, Quick, Heap)
- 常微分方程的幂级数解法
- 6大论坛,30+技术干货议题,2022首届阿里巴巴开源开放周来了!
- C写菜单指令的快捷方法
猜你喜欢
Use tensorboard remotely on the server
深刻地认识到,编译器会导致编译结果的不同
写在光学之前--振动和波
pytorch从零搭建神经网络实现多分类(训练自己的数据集)
Suddenly want to analyze the mortgage interest rate and interest calculation
怎么用VS+Qt创建新项目
ASP.Net Core实战——初识.NetCore
Qt控件-QTextEdit使用记录
[MySql] implement multi-table query - one-to-one, one-to-many
PAT1027 打印沙漏
随机推荐
bin document read and write
复数与复数域
Example of file operations - downloading and merging streaming video files
Servlet的生命周期
redis从入门到精通
贝塞尔函数
Talking about Shallow Cloning and Deep Cloning of ArraryList
【C语言初阶】求最小公倍数的三种方法
浅析Servlet三大容器的常用方法及其作用域
内存泄露检测工具VLD(Visual Leak Detector)使用说明
Welcome to use CSDN - markdown editor
Bessel function
In the process of quantitative trading, retail investors can do this
SNR 信噪比
A shortcut method for writing menu commands in C
记一次解决Mysql:Incorrect string value: ‘\xF0\x9F\x8D\x83\xF0\x9F...‘ for column 插入emoji表情报错问题
分析:通过哪种方法来建立股票量化交易数据库?
What is a template engine?What are the common template engines?Introduction to common commands of thymeleaf.
走得通,看得见!你的交通“好帮手”
利用qrcode组件实现图片转二维码