custom caching

This commit is contained in:
Randall Schmidt
2021-06-11 11:25:24 -04:00
parent 1ae909985e
commit 4cae72dce2
8 changed files with 101 additions and 31 deletions

View File

@ -0,0 +1,16 @@
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);
}
}