使用 lodash throttle 函数时,我遇到了一种情况,需要确保两个网络请求到达服务器时有足够的时间间隔。 由于网络延迟的存在,间隔一秒发送的两次请求,可能同时到达服务器。 我希望第二次请求在第一次请求完成后的一秒再次发起,以确保它们到达服务器的间隔不小于一秒。 是否可以通过 lodash 中现有的 throttle 函数实现这个目标,或者是否有其他推荐的方法? // 为了方便观测, 间隔设置为10秒 export default () => { const sendRequest = () => new Promise((resolve) => setTimeout(resolve, 3000)) // 3s const throttledRequest = throttle( () => { console.log(now(), '执行请求') sendRequest().then(() => console.log(now(), '获得结果')) }, 10000, { leading: true, trailing: true } // 10s ) const triggerRequest = () => { console.log(now(), '触发操作') throttledRequest() } return click } «假设00:00时双击按钮, 第一次请求立即触发, 并在第00:03得到第一次结果; 当前在第00:10发送第二次请求, 00:13得到第二次结果; 希望在第00:13发送第二次请求, 00:16得到第二次结果.(00:03回调后等10秒开始执行第二次请求)»