当前位置:网站首页>Concurrent optimization request
Concurrent optimization request
2022-04-23 06:53:00 【zjLOVEcyj】
// Concurrent optimization 10 A request , At most can be executed at the same time 3 individual
// Input :promise Array ,limit Parameters
// Storage reqPool - Concurrent pool
// Ideas : Insert + perform
function qpsLimit (requestPipe, limitMax=3) {
let reqPool = []
// Insert requests into the concurrency pool
const add = () => {
let req = requestPipe.shift()
reqPool.push(req)
}
// Execute the actual request
const run = () => {
if (requestPipe.length === 0) return
let finsh = Promise.race(reqPool)
finsh.then(res => {
let done = reqPool.indexOf(finsh)
reqPool.splice(done, 1)
add()
})
run()
}
while (reqPool.length < limitMax) {
add()
}
run()
}
版权声明
本文为[zjLOVEcyj]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230555334354.html
边栏推荐
猜你喜欢
随机推荐
Decentralized Collaborative Learning Framework for Next POI Recommendation
时间格式不对,运行sql文件报错
ASP.NET CORE JWT认证
TP5 使用redis
常用sql语句收藏
出入库与库存系统的模型问题
Overview of node file system and buffer
百度地图案例-缩放组件、地图比例组件
PHP 无限极分类和树形
Unity3D对象池的理解与小例子
ASP.NET CORE 配置选项(上篇)
JS handwriting compatibility event binding
swiper组件封装
初步认识Promse
freeCodeCamp----shape_calculator练习
Devexpress Gridview 添加全选列
js中entries(),keys(),values() , some(), Object.assign()遍历数组用法
The difference between VaR, let and Const
端口占用1
不用登录直接下载PNG图标的一个网站