目的:
现有多个异步请求,需要并发请求,并限制并发数。
用例
let request = (delay, id) => {
return new Promise((resolve) => {
setTimeout(resolve, delay, id)
})
}
let test_requests = [
request(6000, 1),
request(3000, 2),
request(4000, 3),
request(6000, 4),
request(1000, 5),
request(2000, 6),
]
Promise解法 (递归)
思路: