{"version":3,"file":"create-timer.mjs","names":[],"sources":["../src/create-timer.ts"],"sourcesContent":["import { assert } from \"./assert.ts\";\nimport type { Fn, TimerId } from \"./types.ts\";\n\nexport function createTimer(\n\tcallback: Fn,\n\tdelay: number,\n): { pause: () => void; resume: () => void } {\n\tassert(Number.isSafeInteger(delay) && delay > 0, \"Delay must be positive integer.\");\n\n\tlet timer: TimerId | null = setTimeout(callback, delay);\n\n\tlet startedAt = performance.now();\n\tlet remaining = delay;\n\n\tfunction pause() {\n\t\tif (timer === null) {\n\t\t\treturn;\n\t\t}\n\n\t\tclearTimeout(timer);\n\t\ttimer = null;\n\t\tremaining -= performance.now() - startedAt;\n\t}\n\n\tfunction resume() {\n\t\tif (timer !== null) {\n\t\t\treturn;\n\t\t}\n\n\t\ttimer = setTimeout(callback, remaining);\n\t\tstartedAt = performance.now();\n\t}\n\n\treturn { pause, resume };\n}\n"],"mappings":";;;AAGA,SAAgB,YACf,UACA,OAC4C;AAC5C,QAAO,OAAO,cAAc,MAAM,IAAI,QAAQ,GAAG,kCAAkC;CAEnF,IAAI,QAAwB,WAAW,UAAU,MAAM;CAEvD,IAAI,YAAY,YAAY,KAAK;CACjC,IAAI,YAAY;CAEhB,SAAS,QAAQ;AAChB,MAAI,UAAU,KACb;AAGD,eAAa,MAAM;AACnB,UAAQ;AACR,eAAa,YAAY,KAAK,GAAG;;CAGlC,SAAS,SAAS;AACjB,MAAI,UAAU,KACb;AAGD,UAAQ,WAAW,UAAU,UAAU;AACvC,cAAY,YAAY,KAAK;;AAG9B,QAAO;EAAE;EAAO;EAAQ"}