move autobind and debouncePromise to common/utils (#1081)

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2020-10-14 14:36:19 +03:00
1 parent 78f6f8ef54
commit 770c6b80f1
8 files changed
+35 -31

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
// Debouncing promise evaluation
export function debouncePromise<T, F extends any[]>(func: (...args: F) => T | Promise<T>, timeout = 0): (...args: F) => Promise<T> {
let timer: NodeJS.Timeout;
return (...params: any[]) => new Promise((resolve, reject) => {
clearTimeout(timer);
timer = setTimeout(() => resolve(func.apply(this, params)), timeout);
});
}