()
| 21 | let timer: number | null = null; |
| 22 | |
| 23 | async function submitQueue() { |
| 24 | timer = null; // 清空计时器以接受后续请求 |
| 25 | const _queue = [...queue]; |
| 26 | queue = []; // 清空队列 |
| 27 | |
| 28 | try { |
| 29 | const list = await fn(_queue.map((q) => q.params)); |
| 30 | _queue.forEach((q1, i) => { |
| 31 | q1.resolve(list[i]); |
| 32 | }); |
| 33 | } catch (err) { |
| 34 | _queue.forEach((q2) => { |
| 35 | q2.reject(err); |
| 36 | }); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | return (params: T): Promise<R> => { |
| 41 | if (!timer) { |
no test coverage detected