当前位置:网站首页>promise all的实现
promise all的实现
2022-04-23 06:25:00 【笔描相思】
function promiseAll(Promises)
{
return new Promise(function(resolve,reject){
if(!Array.isArray(Promises))
{
return reject(new TypeError("argument"));
}
var countNum=0;
var promiseNum=Promises.length;
var resolvedvalue=new Array(promiseNum);
for(let i=0;i<promiseNum;i++)
{
Promise.resolve(Promises[i]).then(function(value){
countNum++;
resolvedvalue[i]=value;
if(countNum===promiseNum)
{
return resolve(resolvedvalue);
}
},function(reason){
return reject(reason);
})
}
})
}
var p1=Promise.resolve(1),
p2=Promise.resolve(2),
p3=Promise.resolve(3);
promiseAll([p1,p2,p3]).then(function(value){
console.log(value)
})
版权声明
本文为[笔描相思]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_44788119/article/details/120903188
边栏推荐
猜你喜欢
h5本地存储数据sessionStorage、localStorage
如何判断点是否在多边形内(包含复杂多边形或者多边形数量很多的情况)
ABAP 实现发布RESTful服务供外部调用示例
SAP pi / PO rfc2soap publishes RFC interface as WS example
SAP pi / PO rfc2restful publishing RFC interface is a restful example (proxy indirect method)
SAP CR传输请求顺序、依赖检查
keytool: command not found
SAP 03-AMDP CDS Table Function using ‘WITH‘ Clause(Join子查询内容)
ABAP CDS VIEW WITH ASSOCIATION示例
Reflection on the systematic design of Android audio and video caching mechanism
随机推荐
Authorization server (simple construction of authorization server)
超级宝典&编程指南(红蓝宝书)-读书笔记
13.用户和权限管理
Visualization Road (IX) detailed explanation of arrow class
SAP ECC连接SAP PI系统配置
How to judge whether a point is within a polygon (including complex polygons or a large number of polygons)
ABAP 7.4 SQL Window Expression
5.SQL99标准:内连接和外连接
ABAP 从CDS VIEW 发布OData Service示例
9. Common functions
手游性能优化
ABAP 实现发布RESTful服务供外部调用示例
积性函数与迪利克雷卷积
Mysql隔离级别
9.常用函数
SAP Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃。
js之预解析
【自我激励系列】你永远不会准备好
反思|开启B站少女心模式,探究APP换肤机制的设计与实现
[CodeForces - 208E] Blood Cousins(k代兄弟问题)