This repository has been archived on 2023-10-27. You can view files and clone it, but cannot push or open issues or pull requests.
node-fetch-cache/classes/caching/key_timeout.js

17 lines
332 B
JavaScript
Raw Normal View History

2021-07-05 18:17:21 +00:00
export class KeyTimeout {
2021-06-12 23:26:05 +00:00
constructor() {
this.timeoutHandleForKey = {};
}
clearTimeout(key) {
clearTimeout(this.timeoutHandleForKey[key]);
}
updateTimeout(key, durationMs, callback) {
this.clearTimeout(key);
this.timeoutHandleForKey[key] = setTimeout(() => {
callback();
}, durationMs);
}
2021-07-05 18:17:21 +00:00
}