Merge pull request #18641 from ramonlsouza/issue-18602

fix: Client crashes when mute microphone while Closed Caption is executing
This commit is contained in:
Anton Georgiev 2023-08-25 14:21:22 -04:00 committed by GitHub
commit b31bf77d27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,14 +5,18 @@ export function throttle(func, delay, options = {}) {
const { leading = true, trailing = true } = options;
return function () {
let cancelPendingExecution = false; // Flag to track cancellation
const throttledFunction = function () {
const context = this;
const args = arguments;
const elapsed = Date.now() - lastExecTime;
function execute() {
func.apply(context, args);
lastExecTime = Date.now();
if (!cancelPendingExecution) { // Only execute if not cancelled
func.apply(context, args);
lastExecTime = Date.now();
}
}
if (leadingExec && leading) {
@ -24,5 +28,14 @@ export function throttle(func, delay, options = {}) {
timeoutId = null;
}, delay - elapsed);
}
}
};
// Add a cancel method to the throttled function
throttledFunction.cancel = function () {
cancelPendingExecution = true;
clearTimeout(timeoutId);
timeoutId = null;
};
return throttledFunction;
}