1๐
โ
Do it naive way.
const ELAPSE_TIME = 3000; // 3 second
let oldCommand;
let lastTime;
function update() {
if (buttonIsPressed) {
const command = getCurrentCommand();
if (command !== oldCommand) { // command has changed
lastTime = new Date().getTime();
} else { // command has not changed
let now = new Date().getTime();
let duration = now - lastTime;
if (duration > ELAPSE_TIME) { // already 3 second
postUpdate();
lastTime = now - ELAPSE_TIME;
}
}
}
}
setInterval(update, 100);
๐คDaniel Tran
Source:stackexchange.com