当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Solution to page cache problem (use with caution)
1-1 NodeJS
el-cascader和el-select点击别处让下拉框消失
Node模版引擎(ejs, art-template)
WebAPI+Form表单上传文件
TP5 error reporting variable type error: array solution
SiteServer CMS5.0使用总结
【关于数据库的简易认识】
各进制数之间的互相转换
百度地图基础案例
时间格式不对,运行sql文件报错
leetcode刷题之二进制求和
file_get_contents 访问 ssl 错误的两种解决方法
The difference between VaR, let and Const
启用AHCI后无法启动系统
mysql密码过期的方法
fdfs启动
TP5 使用redis
低代码开发平台整理
数据可视化基础了解