MCPcopy
hub / github.com/tldraw/tldraw / fn

Function fn

packages/utils/src/lib/debounce.ts:66–89  ·  view source on GitHub ↗
(...args: T)

Source from the content-addressed store, hash-verified

64 } = undefined
65
66 const fn = (...args: T): Promise<U> => {
67 if (!state) {
68 state = {} as any
69 state!.promise = new Promise((resolve, reject) => {
70 state!.resolve = resolve
71 state!.reject = reject
72 })
73 }
74 clearTimeout(state!.timeout)
75 state!.latestArgs = args
76 // It's up to the consumer of debounce to call `cancel`
77 // eslint-disable-next-line no-restricted-globals
78 state!.timeout = setTimeout(() => {
79 const s = state!
80 state = undefined
81 try {
82 s.resolve(callback(...s.latestArgs))
83 } catch (e) {
84 s.reject(e)
85 }
86 }, wait)
87
88 return state!.promise
89 }
90 fn.cancel = () => {
91 if (!state) return
92 clearTimeout(state.timeout)

Callers 15

minByFunction · 0.70
maxByFunction · 0.70
wrappedFnFunction · 0.70
retryFunction · 0.70
flushMethod · 0.70
throttleToNextFrameMethod · 0.70
usingObjectURLMethod · 0.50
expectValidFunction · 0.50
expectForbiddenFunction · 0.50
expectBadRequestFunction · 0.50
readEnvFunction · 0.50
useEventFunction · 0.50

Calls 2

resolveMethod · 0.65
rejectMethod · 0.65

Tested by 3

expectValidFunction · 0.40
expectForbiddenFunction · 0.40
expectBadRequestFunction · 0.40