Like a standard debounce from e.g. micro-dash, but can execute a different function for a different wait period at each invocation.
micro-dash
const print = (value) => console.log(value);const debouncer = new Debouncer();debouncer.run(print, 1000, 1);await sleep(500);debouncer.run(print, 1000, 2);await sleep(1000); // prints "2"debouncer.run(print, 0, 3);debouncer.run(print, 1000, 4);await sleep(500);debouncer.run(print, 2000, 5);debouncer.run(print, 50, 6);await sleep(50); // prints "6" Copy
const print = (value) => console.log(value);const debouncer = new Debouncer();debouncer.run(print, 1000, 1);await sleep(500);debouncer.run(print, 1000, 2);await sleep(1000); // prints "2"debouncer.run(print, 0, 3);debouncer.run(print, 1000, 4);await sleep(500);debouncer.run(print, 2000, 5);debouncer.run(print, 50, 6);await sleep(50); // prints "6"
Like a standard debounce from e.g.
micro-dash, but can execute a different function for a different wait period at each invocation.