MCPcopy
hub / github.com/prisma/prisma / simpleDebounce

Function simpleDebounce

packages/cli/src/utils/simpleDebounce.ts:6–23  ·  view source on GitHub ↗
(fn: T)

Source from the content-addressed store, hash-verified

4
5/* eslint-disable @typescript-eslint/no-explicit-any */
6export function simpleDebounce<T extends Function>(fn: T): T {
7 let executing = false
8 let pendingExecution: any = null
9 return (async (...args) => {
10 if (executing) {
11 // if there are 2 executions 50ms apart, ignore the last one
12 pendingExecution = args
13 return null as any
14 }
15 executing = true
16 await fn(...args).catch((e) => console.error(e))
17 if (pendingExecution) {
18 await fn(...pendingExecution).catch((e) => console.error(e))
19 pendingExecution = null
20 }
21 executing = false
22 }) as any
23}
24/* eslint-enable @typescript-eslint/no-explicit-any */

Callers 1

GenerateClass · 0.90

Calls 3

catchMethod · 0.80
errorMethod · 0.80
fnFunction · 0.50

Tested by

no test coverage detected