openc3-cosmos-init/plugins/packages/openc3-cosmos-ace-diff/src/helpers/throttle.js
export default function throttle(callback, wait, immediate = false) {
let timeout = null
let initialCall = true
return (...args) => {
const callNow = immediate && initialCall
const next = () => {
callback.apply(this, args)
timeout = null
}
if (callNow) {
initialCall = false
next()
}
if (!timeout) {
timeout = setTimeout(next, wait)
}
}
}