custom caching

This commit is contained in:
Randall Schmidt
2021-06-11 11:25:24 -04:00
parent ad256800f8
commit 831440152a
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);
}
}