当前位置:网站首页>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
边栏推荐
猜你喜欢

redis连接出错 ERR AUTH <password> called without any password configured for the default user.

BTREE, B + tree and hash index

数论分块(整除分块)

Visualization Road (IX) detailed explanation of arrow class

Date对象(js内置对象)

js之节点操作,为什么要学习节点操作

SAP PI / Po rfc2restful Publishing RFC interface as restful examples (proxy indirect)

SAP CR传输请求顺序、依赖检查

SAP PI/PO登录使用及基本功能简介

SAP 导出Excel文件打开显示:“xxx“的文件格式和扩展名不匹配。文件可能已损坏或不安全。除非您信任其来源,否则请勿打开。是否仍要打开它?
随机推荐
[CodeForces - 208E] Blood Cousins(k代兄弟问题)
(扩展)BSGS与高次同余方程
F-牛妹的苹果树(直径合并)
ABAP 7.4 SQL Window Expression
[hdu6868]Absolute Math(推式子+莫比乌斯反演)
配置npm
SAP pi / PO rfc2restful publishing RFC interface is a restful example (proxy indirect method)
OpenGL超级宝典初步配置(freeglut、glew、gltools、glut)
AuthorizationServer(授权服务器的简单搭建)
Thorough inquiry -- understanding and analysis of cocos2d source code
Solutions to common problems in visualization (VII) solutions to drawing scale setting
数据分析入门 | kaggle泰坦尼克任务(四)—>数据清洗及特征处理
SAP PI / Po rfc2restful Publishing RFC interface as restful examples (proxy indirect)
7. sub query
刨根问底---cocos2d源码的理解与分析
Background management system framework, there is always what you want
Mvcc (multi version concurrency control)
ogldev-读书笔记
CSDN很火的汤小洋老师全部课程总共有哪些(问号问号问号)
MVCC(多版本并发控制)