{"version":3,"sources":["../src/lib/debouncer.ts"],"sourcesContent":["export type AsyncFunction<T extends any[]> = (...args: [...T, AbortSignal]) => Promise<void>;\n\nexport class Debouncer<T extends any[]> {\n  private timeoutId?: ReturnType<typeof setTimeout>;\n  private activeAbortController?: AbortController;\n\n  constructor(private wait: number) {}\n\n  debounce = async (func: AsyncFunction<T>, ...args: T) => {\n    // Abort the previous promise immediately\n    this.cancel();\n\n    this.timeoutId = setTimeout(async () => {\n      try {\n        this.activeAbortController = new AbortController();\n\n        // Pass the signal to the async function, assuming it supports it\n        await func(...args, this.activeAbortController.signal);\n\n        this.activeAbortController = undefined;\n      } catch (error) {}\n    }, this.wait);\n  };\n\n  cancel = () => {\n    if (this.activeAbortController) {\n      this.activeAbortController.abort();\n      this.activeAbortController = undefined;\n    }\n\n    if (this.timeoutId !== undefined) {\n      clearTimeout(this.timeoutId);\n      this.timeoutId = undefined;\n    }\n  };\n}\n"],"mappings":";;;;;AAEO,IAAM,YAAN,MAAiC;AAAA,EAItC,YAAoB,MAAc;AAAd;AAEpB,oBAAW,CAAO,SAA2B,SAAY;AAEvD,WAAK,OAAO;AAEZ,WAAK,YAAY,WAAW,MAAY;AACtC,YAAI;AACF,eAAK,wBAAwB,IAAI,gBAAgB;AAGjD,gBAAM,KAAK,GAAG,MAAM,KAAK,sBAAsB,MAAM;AAErD,eAAK,wBAAwB;AAAA,QAC/B,SAAS,OAAP;AAAA,QAAe;AAAA,MACnB,IAAG,KAAK,IAAI;AAAA,IACd;AAEA,kBAAS,MAAM;AACb,UAAI,KAAK,uBAAuB;AAC9B,aAAK,sBAAsB,MAAM;AACjC,aAAK,wBAAwB;AAAA,MAC/B;AAEA,UAAI,KAAK,cAAc,QAAW;AAChC,qBAAa,KAAK,SAAS;AAC3B,aAAK,YAAY;AAAA,MACnB;AAAA,IACF;AAAA,EA5BmC;AA6BrC;","names":[]}