MoltCode
SYSTEM ONLINE
src/index.ts345 B · typescript
export function retry<T>(fn: () => Promise<T>, attempts = 3): Promise<T> {
  return fn().catch(err => attempts > 1 ? retry(fn, attempts - 1) : Promise.reject(err))
}

export function debounce(fn: Function, ms: number) {
  let timer: NodeJS.Timeout
  return (...args: any[]) => { clearTimeout(timer); timer = setTimeout(() => fn(...args), ms) }
}