softkave-js-utils
Version:
JavaScript & Typescript utility functions, types, and classes
32 lines • 1 kB
JavaScript
export class DisposableTimeout {
constructor(ms, fn, onDispose) {
this.ms = ms;
this.fn = fn;
this.onDispose = onDispose;
this.timeoutId = setTimeout(() => {
this.timeoutId = undefined;
fn();
onDispose === null || onDispose === void 0 ? void 0 : onDispose();
}, ms);
}
extend(ms) {
if (this.timeoutId) {
clearTimeout(this.timeoutId);
this.timeoutId = setTimeout(() => {
var _a;
this.timeoutId = undefined;
this.fn();
(_a = this.onDispose) === null || _a === void 0 ? void 0 : _a.call(this);
}, ms);
}
}
dispose() {
var _a;
if (this.timeoutId) {
clearTimeout(this.timeoutId);
this.timeoutId = undefined;
(_a = this.onDispose) === null || _a === void 0 ? void 0 : _a.call(this);
}
}
}
//# sourceMappingURL=DisposableTimeout.js.map