chrome-devtools-frontend
Version:
Chrome DevTools UI
16 lines (14 loc) • 555 B
text/typescript
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* Debounce utility function, ensures that the function passed in is only called once the function stops being called and the delay has expired.
*/
export const debounce = function(func: () => void, delay: number): () => void {
let timer = 0;
const debounced = (): void => {
clearTimeout(timer);
timer = window.setTimeout(() => func(), delay);
};
return debounced;
};