update rAF handle in timeout_handlers so that it is cleared with clearAllTimeouts

This commit is contained in:
Becky Gilbert 2021-04-27 15:44:06 -07:00
parent 2214115e44
commit 16e51aa2fc

View File

@ -2560,10 +2560,12 @@ jsPsych.pluginAPI = (function() {
if (curr_duration >= delay - 8) { if (curr_duration >= delay - 8) {
callback(curr_duration); callback(curr_duration);
} else { } else {
// setup the next rAF call and update handle value // remove the old rAF handle from timeout_handlers, setup the next rAF call, and update handle and timeout_handlers
timeout_handlers = timeout_handlers.filter(function(el) { return el !== handle; });
handle = requestAnimationFrame(function(timestamp) { handle = requestAnimationFrame(function(timestamp) {
checkForTimeouts(timestamp, start_time, callback, delay, handle); checkForTimeouts(timestamp, start_time, callback, delay, handle);
}); });
timeout_handlers.push(handle);
} }
} }