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

This commit is contained in:
Becky Gilbert 2021-04-27 15:45:40 -07:00
parent 29449e21e3
commit 1b7ef52327

View File

@ -2557,10 +2557,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);
} }
} }