@fs-eire/wgsl-template
Version:
A powerful template system for generating WGSL (WebGPU Shading Language) code with support for parameters, conditionals, and multiple output formats including C++ code generation.
39 lines • 945 B
JavaScript
/**
* Simple debouncer utility for batching rapid events
*/
export class Debouncer {
timeoutId = null;
delay;
constructor(delay = 300) {
this.delay = delay;
}
/**
* Debounce a function call. If called again before the delay expires,
* the previous call is cancelled and a new timer is started.
*/
debounce(fn) {
if (this.timeoutId) {
clearTimeout(this.timeoutId);
}
this.timeoutId = setTimeout(async () => {
this.timeoutId = null;
await fn();
}, this.delay);
}
/**
* Cancel any pending debounced call
*/
cancel() {
if (this.timeoutId) {
clearTimeout(this.timeoutId);
this.timeoutId = null;
}
}
/**
* Check if there's a pending debounced call
*/
isPending() {
return this.timeoutId !== null;
}
}
//# sourceMappingURL=debouncer.js.map