1、限制并发数量

全部并发

promise.all

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const urls = [
'https://api.example.com/data1',
'https://api.example.com/data2',
'https://api.example.com/data3'
];

// 把每个 URL 变成一个 fetch Promise
const promises = urls.map(url => fetch(url).then(response => response.json()));

// 用 Promise.all 并发执行
Promise.all(promises)
.then(results => {
console.log('全部请求成功:', results);
})
.catch(error => {
console.error('有请求失败:', error);
});

promise.allSettled

1
2


分批并发

限制并发

2、请求排队(串行执行)

3、防抖(debounce)

4、节流(throttle)

5、请求锁(防止重复请求)

6、请求取消(AbortController)

7、竞态请求处理


文章来源于