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

tp5 报错variable type error: array解决方法

Decentralized Collaborative Learning Framework for Next POI Recommendation

数据可视化进一步学习

Installing redis using a small leather panel in the window environment

try --finally

Devexpress Gridview 添加全选列

JS实现网页轮播图

若依如何input改成文本

1-4 NodeJS的安装之配置可执行脚本

Leak detection and vacancy filling (II)
随机推荐
useCenterHook
常用sql语句收藏
JS实现网页轮播图
Overview of node file system and buffer
postMan 传参总结
数据可视化百度地图进一步优化
China creates vast research infrastructure to support ambitious climate goals
2021-09-18
.Net Core 下使用 Quartz —— 【5】作业和触发器之触发器的通用属性和优先级
.NET Standard详解
The time format is incorrect, and an error is reported when running the SQL file
Unity3D对象池的理解与小例子
Counts the number of occurrences of each character in the string
百度地图坐标、Google坐标、腾讯坐标相互转化
数据可视化进一步学习
Usage of if conditional statements in SQL
页面缓存问题解决方法(慎用)
Navicat 连接 oracle library is not loaded的解决方法
【Markdown笔记】
手动实现call,apply,bind函数