aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/debounce.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/debounce.ts')
-rw-r--r--server/helpers/debounce.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/server/helpers/debounce.ts b/server/helpers/debounce.ts
new file mode 100644
index 000000000..77d99a894
--- /dev/null
+++ b/server/helpers/debounce.ts
@@ -0,0 +1,16 @@
1export function Debounce (config: { timeoutMS: number }) {
2 let timeoutRef: NodeJS.Timeout
3
4 return function (_target, _key, descriptor: PropertyDescriptor) {
5 const original = descriptor.value
6
7 descriptor.value = function (...args: any[]) {
8 clearTimeout(timeoutRef)
9
10 timeoutRef = setTimeout(() => {
11 original.apply(this, args)
12
13 }, config.timeoutMS)
14 }
15 }
16}