16 lines
341 B
JavaScript
16 lines
341 B
JavaScript
|
module.exports = class KeyTimeout {
|
||
|
constructor() {
|
||
|
this.timeoutHandleForKey = {};
|
||
|
}
|
||
|
|
||
|
clearTimeout(key) {
|
||
|
clearTimeout(this.timeoutHandleForKey[key]);
|
||
|
}
|
||
|
|
||
|
updateTimeout(key, durationMs, callback) {
|
||
|
this.clearTimeout(key);
|
||
|
this.timeoutHandleForKey[key] = setTimeout(() => {
|
||
|
callback();
|
||
|
}, durationMs);
|
||
|
}
|
||
|
}
|