function multiRequest(urls, max) { return new Promise((resolve, reject) => { const requestRes = {} const len = urls.length //总大小 let finshedCount = 0 //已完成 let running = 0 // 正在请求中 let index = 0 function addQueue() { index++ running += 1 fetch(urls[index]).then(res => { requestRes[index - max] = res }).catch(err => { requestRes[index - max] = err }).finally(() => { running -= 1 finshedCount += 1 if (running < max && finshedCount < len) { addQueue() } if (finshedCount == len) { resolve(Array.from({ ...requestRes, length: len })) } }) if (running < max && finshedCount < len) { addQueue() } } addQueue() }) }
点赞 评论

相关推荐

昨天 11:08
门头沟学院 Java
投递京东等公司9个岗位
点赞 评论 收藏
分享
05-26 16:13
门头沟学院 C++
牢大肘击Java:海投就完事了bro,就当刷视频了
点赞 评论 收藏
分享
05-21 15:47
门头沟学院 Java
浪漫主义的虹夏:项目有亮点吗,第一个不是纯玩具项目吗,项目亮点里类似ThreadLocal,Redis储存说难听点是花几十分钟绝大部分人都能学会,第二个轮子项目也没体现出设计和技术,想实习先沉淀,好高骛远的自嗨只会害了自己
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务