@xylabs/timer 3.6.7 → 3.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.cjs +1 -1
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.mjs +1 -1
- package/dist/browser/index.mjs.map +1 -1
- package/dist/neutral/index.cjs +1 -1
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.mjs +1 -1
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +1 -1
- package/dist/node/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/setTimeoutEx.ts +13 -13
package/dist/browser/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/setTimeoutEx.ts"],"sourcesContent":["export * from './setTimeoutEx.ts'\n","import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/setTimeoutEx.ts"],"sourcesContent":["export * from './setTimeoutEx.ts'\n","import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n func: Function\n id: string\n}\n\nlet timeouts: TimeoutInfo[] = []\nlet currentTimeout: NodeJS.Timeout | undefined\nlet interval = -1\n\nconst reset = () => {\n interval = -1\n clearTimeout(currentTimeout)\n currentTimeout = undefined\n timeouts = []\n}\n\nconst update = (newTimeouts = timeouts, delayPassed = 0) => {\n // if no more timeouts, set back to initial state\n if (newTimeouts.length <= 0) {\n reset()\n } else {\n const newInterval = Math.min(...newTimeouts.map(timeout => timeout.delay))\n\n if (newInterval === interval && currentTimeout !== undefined) {\n // since nothing changed, just return\n return\n } else {\n clearTimeout(currentTimeout)\n timeouts = newTimeouts.map(timeout => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }))\n // restart timeout since it needs to be different\n interval = newInterval\n currentTimeout = setTimeout(timerFunc, interval)\n }\n }\n}\n\nconst timerFunc = () => {\n const notFiring = timeouts.filter(timeout => timeout.delay > interval)\n const firing = timeouts.filter(timeout => timeout.delay <= interval)\n\n // call this after getting notFiring and firing since set will change in this call\n update(notFiring, interval)\n\n // trigger the ones that need to be triggered\n for (const timeout of firing) {\n timeout.func()\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const setTimeoutEx = (func: Function, delay: number) => {\n assertEx(delay >= 0, () => 'delay must be >= 0')\n const id = `${Date.now()}|${Math.random() * 9_999_999_999}`\n timeouts.push({ delay, func, id })\n update()\n return id\n}\n\nexport const clearTimeoutEx = (id: string) => {\n timeouts = timeouts.filter(timeout => timeout.id !== id)\n update(timeouts)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AASzB,IAAI,WAA0B,CAAC;AAC/B,IAAI;AACJ,IAAI,WAAW;AAEf,IAAM,QAAQ,MAAM;AAClB,aAAW;AACX,eAAa,cAAc;AAC3B,mBAAiB;AACjB,aAAW,CAAC;AACd;AAEA,IAAM,SAAS,CAAC,cAAc,UAAU,cAAc,MAAM;AAE1D,MAAI,YAAY,UAAU,GAAG;AAC3B,UAAM;AAAA,EACR,OAAO;AACL,UAAM,cAAc,KAAK,IAAI,GAAG,YAAY,IAAI,aAAW,QAAQ,KAAK,CAAC;AAEzE,QAAI,gBAAgB,YAAY,mBAAmB,QAAW;AAE5D;AAAA,IACF,OAAO;AACL,mBAAa,cAAc;AAC3B,iBAAW,YAAY,IAAI,cAAY,EAAE,OAAO,QAAQ,QAAQ,aAAa,MAAM,QAAQ,MAAM,IAAI,QAAQ,GAAG,EAAE;AAElH,iBAAW;AACX,uBAAiB,WAAW,WAAW,QAAQ;AAAA,IACjD;AAAA,EACF;AACF;AAEA,IAAM,YAAY,MAAM;AACtB,QAAM,YAAY,SAAS,OAAO,aAAW,QAAQ,QAAQ,QAAQ;AACrE,QAAM,SAAS,SAAS,OAAO,aAAW,QAAQ,SAAS,QAAQ;AAGnE,SAAO,WAAW,QAAQ;AAG1B,aAAW,WAAW,QAAQ;AAC5B,YAAQ,KAAK;AAAA,EACf;AACF;AAGO,IAAM,eAAe,CAAC,MAAgB,UAAkB;AAC7D,8BAAS,SAAS,GAAG,MAAM,oBAAoB;AAC/C,QAAM,KAAK,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,UAAa;AACzD,WAAS,KAAK,EAAE,OAAO,MAAM,GAAG,CAAC;AACjC,SAAO;AACP,SAAO;AACT;AAEO,IAAM,iBAAiB,CAAC,OAAe;AAC5C,aAAW,SAAS,OAAO,aAAW,QAAQ,OAAO,EAAE;AACvD,SAAO,QAAQ;AACjB;","names":[]}
|
package/dist/browser/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/setTimeoutEx.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/
|
|
1
|
+
{"version":3,"sources":["../../src/setTimeoutEx.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n func: Function\n id: string\n}\n\nlet timeouts: TimeoutInfo[] = []\nlet currentTimeout: NodeJS.Timeout | undefined\nlet interval = -1\n\nconst reset = () => {\n interval = -1\n clearTimeout(currentTimeout)\n currentTimeout = undefined\n timeouts = []\n}\n\nconst update = (newTimeouts = timeouts, delayPassed = 0) => {\n // if no more timeouts, set back to initial state\n if (newTimeouts.length <= 0) {\n reset()\n } else {\n const newInterval = Math.min(...newTimeouts.map(timeout => timeout.delay))\n\n if (newInterval === interval && currentTimeout !== undefined) {\n // since nothing changed, just return\n return\n } else {\n clearTimeout(currentTimeout)\n timeouts = newTimeouts.map(timeout => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }))\n // restart timeout since it needs to be different\n interval = newInterval\n currentTimeout = setTimeout(timerFunc, interval)\n }\n }\n}\n\nconst timerFunc = () => {\n const notFiring = timeouts.filter(timeout => timeout.delay > interval)\n const firing = timeouts.filter(timeout => timeout.delay <= interval)\n\n // call this after getting notFiring and firing since set will change in this call\n update(notFiring, interval)\n\n // trigger the ones that need to be triggered\n for (const timeout of firing) {\n timeout.func()\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const setTimeoutEx = (func: Function, delay: number) => {\n assertEx(delay >= 0, () => 'delay must be >= 0')\n const id = `${Date.now()}|${Math.random() * 9_999_999_999}`\n timeouts.push({ delay, func, id })\n update()\n return id\n}\n\nexport const clearTimeoutEx = (id: string) => {\n timeouts = timeouts.filter(timeout => timeout.id !== id)\n update(timeouts)\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AASzB,IAAI,WAA0B,CAAC;AAC/B,IAAI;AACJ,IAAI,WAAW;AAEf,IAAM,QAAQ,MAAM;AAClB,aAAW;AACX,eAAa,cAAc;AAC3B,mBAAiB;AACjB,aAAW,CAAC;AACd;AAEA,IAAM,SAAS,CAAC,cAAc,UAAU,cAAc,MAAM;AAE1D,MAAI,YAAY,UAAU,GAAG;AAC3B,UAAM;AAAA,EACR,OAAO;AACL,UAAM,cAAc,KAAK,IAAI,GAAG,YAAY,IAAI,aAAW,QAAQ,KAAK,CAAC;AAEzE,QAAI,gBAAgB,YAAY,mBAAmB,QAAW;AAE5D;AAAA,IACF,OAAO;AACL,mBAAa,cAAc;AAC3B,iBAAW,YAAY,IAAI,cAAY,EAAE,OAAO,QAAQ,QAAQ,aAAa,MAAM,QAAQ,MAAM,IAAI,QAAQ,GAAG,EAAE;AAElH,iBAAW;AACX,uBAAiB,WAAW,WAAW,QAAQ;AAAA,IACjD;AAAA,EACF;AACF;AAEA,IAAM,YAAY,MAAM;AACtB,QAAM,YAAY,SAAS,OAAO,aAAW,QAAQ,QAAQ,QAAQ;AACrE,QAAM,SAAS,SAAS,OAAO,aAAW,QAAQ,SAAS,QAAQ;AAGnE,SAAO,WAAW,QAAQ;AAG1B,aAAW,WAAW,QAAQ;AAC5B,YAAQ,KAAK;AAAA,EACf;AACF;AAGO,IAAM,eAAe,CAAC,MAAgB,UAAkB;AAC7D,WAAS,SAAS,GAAG,MAAM,oBAAoB;AAC/C,QAAM,KAAK,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,UAAa;AACzD,WAAS,KAAK,EAAE,OAAO,MAAM,GAAG,CAAC;AACjC,SAAO;AACP,SAAO;AACT;AAEO,IAAM,iBAAiB,CAAC,OAAe;AAC5C,aAAW,SAAS,OAAO,aAAW,QAAQ,OAAO,EAAE;AACvD,SAAO,QAAQ;AACjB;","names":[]}
|
package/dist/neutral/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/setTimeoutEx.ts"],"sourcesContent":["export * from './setTimeoutEx.ts'\n","import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/setTimeoutEx.ts"],"sourcesContent":["export * from './setTimeoutEx.ts'\n","import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n func: Function\n id: string\n}\n\nlet timeouts: TimeoutInfo[] = []\nlet currentTimeout: NodeJS.Timeout | undefined\nlet interval = -1\n\nconst reset = () => {\n interval = -1\n clearTimeout(currentTimeout)\n currentTimeout = undefined\n timeouts = []\n}\n\nconst update = (newTimeouts = timeouts, delayPassed = 0) => {\n // if no more timeouts, set back to initial state\n if (newTimeouts.length <= 0) {\n reset()\n } else {\n const newInterval = Math.min(...newTimeouts.map(timeout => timeout.delay))\n\n if (newInterval === interval && currentTimeout !== undefined) {\n // since nothing changed, just return\n return\n } else {\n clearTimeout(currentTimeout)\n timeouts = newTimeouts.map(timeout => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }))\n // restart timeout since it needs to be different\n interval = newInterval\n currentTimeout = setTimeout(timerFunc, interval)\n }\n }\n}\n\nconst timerFunc = () => {\n const notFiring = timeouts.filter(timeout => timeout.delay > interval)\n const firing = timeouts.filter(timeout => timeout.delay <= interval)\n\n // call this after getting notFiring and firing since set will change in this call\n update(notFiring, interval)\n\n // trigger the ones that need to be triggered\n for (const timeout of firing) {\n timeout.func()\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const setTimeoutEx = (func: Function, delay: number) => {\n assertEx(delay >= 0, () => 'delay must be >= 0')\n const id = `${Date.now()}|${Math.random() * 9_999_999_999}`\n timeouts.push({ delay, func, id })\n update()\n return id\n}\n\nexport const clearTimeoutEx = (id: string) => {\n timeouts = timeouts.filter(timeout => timeout.id !== id)\n update(timeouts)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AASzB,IAAI,WAA0B,CAAC;AAC/B,IAAI;AACJ,IAAI,WAAW;AAEf,IAAM,QAAQ,MAAM;AAClB,aAAW;AACX,eAAa,cAAc;AAC3B,mBAAiB;AACjB,aAAW,CAAC;AACd;AAEA,IAAM,SAAS,CAAC,cAAc,UAAU,cAAc,MAAM;AAE1D,MAAI,YAAY,UAAU,GAAG;AAC3B,UAAM;AAAA,EACR,OAAO;AACL,UAAM,cAAc,KAAK,IAAI,GAAG,YAAY,IAAI,aAAW,QAAQ,KAAK,CAAC;AAEzE,QAAI,gBAAgB,YAAY,mBAAmB,QAAW;AAE5D;AAAA,IACF,OAAO;AACL,mBAAa,cAAc;AAC3B,iBAAW,YAAY,IAAI,cAAY,EAAE,OAAO,QAAQ,QAAQ,aAAa,MAAM,QAAQ,MAAM,IAAI,QAAQ,GAAG,EAAE;AAElH,iBAAW;AACX,uBAAiB,WAAW,WAAW,QAAQ;AAAA,IACjD;AAAA,EACF;AACF;AAEA,IAAM,YAAY,MAAM;AACtB,QAAM,YAAY,SAAS,OAAO,aAAW,QAAQ,QAAQ,QAAQ;AACrE,QAAM,SAAS,SAAS,OAAO,aAAW,QAAQ,SAAS,QAAQ;AAGnE,SAAO,WAAW,QAAQ;AAG1B,aAAW,WAAW,QAAQ;AAC5B,YAAQ,KAAK;AAAA,EACf;AACF;AAGO,IAAM,eAAe,CAAC,MAAgB,UAAkB;AAC7D,8BAAS,SAAS,GAAG,MAAM,oBAAoB;AAC/C,QAAM,KAAK,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,UAAa;AACzD,WAAS,KAAK,EAAE,OAAO,MAAM,GAAG,CAAC;AACjC,SAAO;AACP,SAAO;AACT;AAEO,IAAM,iBAAiB,CAAC,OAAe;AAC5C,aAAW,SAAS,OAAO,aAAW,QAAQ,OAAO,EAAE;AACvD,SAAO,QAAQ;AACjB;","names":[]}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/setTimeoutEx.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/
|
|
1
|
+
{"version":3,"sources":["../../src/setTimeoutEx.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n func: Function\n id: string\n}\n\nlet timeouts: TimeoutInfo[] = []\nlet currentTimeout: NodeJS.Timeout | undefined\nlet interval = -1\n\nconst reset = () => {\n interval = -1\n clearTimeout(currentTimeout)\n currentTimeout = undefined\n timeouts = []\n}\n\nconst update = (newTimeouts = timeouts, delayPassed = 0) => {\n // if no more timeouts, set back to initial state\n if (newTimeouts.length <= 0) {\n reset()\n } else {\n const newInterval = Math.min(...newTimeouts.map(timeout => timeout.delay))\n\n if (newInterval === interval && currentTimeout !== undefined) {\n // since nothing changed, just return\n return\n } else {\n clearTimeout(currentTimeout)\n timeouts = newTimeouts.map(timeout => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }))\n // restart timeout since it needs to be different\n interval = newInterval\n currentTimeout = setTimeout(timerFunc, interval)\n }\n }\n}\n\nconst timerFunc = () => {\n const notFiring = timeouts.filter(timeout => timeout.delay > interval)\n const firing = timeouts.filter(timeout => timeout.delay <= interval)\n\n // call this after getting notFiring and firing since set will change in this call\n update(notFiring, interval)\n\n // trigger the ones that need to be triggered\n for (const timeout of firing) {\n timeout.func()\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const setTimeoutEx = (func: Function, delay: number) => {\n assertEx(delay >= 0, () => 'delay must be >= 0')\n const id = `${Date.now()}|${Math.random() * 9_999_999_999}`\n timeouts.push({ delay, func, id })\n update()\n return id\n}\n\nexport const clearTimeoutEx = (id: string) => {\n timeouts = timeouts.filter(timeout => timeout.id !== id)\n update(timeouts)\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AASzB,IAAI,WAA0B,CAAC;AAC/B,IAAI;AACJ,IAAI,WAAW;AAEf,IAAM,QAAQ,MAAM;AAClB,aAAW;AACX,eAAa,cAAc;AAC3B,mBAAiB;AACjB,aAAW,CAAC;AACd;AAEA,IAAM,SAAS,CAAC,cAAc,UAAU,cAAc,MAAM;AAE1D,MAAI,YAAY,UAAU,GAAG;AAC3B,UAAM;AAAA,EACR,OAAO;AACL,UAAM,cAAc,KAAK,IAAI,GAAG,YAAY,IAAI,aAAW,QAAQ,KAAK,CAAC;AAEzE,QAAI,gBAAgB,YAAY,mBAAmB,QAAW;AAE5D;AAAA,IACF,OAAO;AACL,mBAAa,cAAc;AAC3B,iBAAW,YAAY,IAAI,cAAY,EAAE,OAAO,QAAQ,QAAQ,aAAa,MAAM,QAAQ,MAAM,IAAI,QAAQ,GAAG,EAAE;AAElH,iBAAW;AACX,uBAAiB,WAAW,WAAW,QAAQ;AAAA,IACjD;AAAA,EACF;AACF;AAEA,IAAM,YAAY,MAAM;AACtB,QAAM,YAAY,SAAS,OAAO,aAAW,QAAQ,QAAQ,QAAQ;AACrE,QAAM,SAAS,SAAS,OAAO,aAAW,QAAQ,SAAS,QAAQ;AAGnE,SAAO,WAAW,QAAQ;AAG1B,aAAW,WAAW,QAAQ;AAC5B,YAAQ,KAAK;AAAA,EACf;AACF;AAGO,IAAM,eAAe,CAAC,MAAgB,UAAkB;AAC7D,WAAS,SAAS,GAAG,MAAM,oBAAoB;AAC/C,QAAM,KAAK,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,UAAa;AACzD,WAAS,KAAK,EAAE,OAAO,MAAM,GAAG,CAAC;AACjC,SAAO;AACP,SAAO;AACT;AAEO,IAAM,iBAAiB,CAAC,OAAe;AAC5C,aAAW,SAAS,OAAO,aAAW,QAAQ,OAAO,EAAE;AACvD,SAAO,QAAQ;AACjB;","names":[]}
|
package/dist/node/index.cjs
CHANGED
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/setTimeoutEx.ts"],"sourcesContent":["export * from './setTimeoutEx.ts'\n","import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/setTimeoutEx.ts"],"sourcesContent":["export * from './setTimeoutEx.ts'\n","import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n func: Function\n id: string\n}\n\nlet timeouts: TimeoutInfo[] = []\nlet currentTimeout: NodeJS.Timeout | undefined\nlet interval = -1\n\nconst reset = () => {\n interval = -1\n clearTimeout(currentTimeout)\n currentTimeout = undefined\n timeouts = []\n}\n\nconst update = (newTimeouts = timeouts, delayPassed = 0) => {\n // if no more timeouts, set back to initial state\n if (newTimeouts.length <= 0) {\n reset()\n } else {\n const newInterval = Math.min(...newTimeouts.map(timeout => timeout.delay))\n\n if (newInterval === interval && currentTimeout !== undefined) {\n // since nothing changed, just return\n return\n } else {\n clearTimeout(currentTimeout)\n timeouts = newTimeouts.map(timeout => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }))\n // restart timeout since it needs to be different\n interval = newInterval\n currentTimeout = setTimeout(timerFunc, interval)\n }\n }\n}\n\nconst timerFunc = () => {\n const notFiring = timeouts.filter(timeout => timeout.delay > interval)\n const firing = timeouts.filter(timeout => timeout.delay <= interval)\n\n // call this after getting notFiring and firing since set will change in this call\n update(notFiring, interval)\n\n // trigger the ones that need to be triggered\n for (const timeout of firing) {\n timeout.func()\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const setTimeoutEx = (func: Function, delay: number) => {\n assertEx(delay >= 0, () => 'delay must be >= 0')\n const id = `${Date.now()}|${Math.random() * 9_999_999_999}`\n timeouts.push({ delay, func, id })\n update()\n return id\n}\n\nexport const clearTimeoutEx = (id: string) => {\n timeouts = timeouts.filter(timeout => timeout.id !== id)\n update(timeouts)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AASzB,IAAI,WAA0B,CAAC;AAC/B,IAAI;AACJ,IAAI,WAAW;AAEf,IAAM,QAAQ,MAAM;AAClB,aAAW;AACX,eAAa,cAAc;AAC3B,mBAAiB;AACjB,aAAW,CAAC;AACd;AAEA,IAAM,SAAS,CAAC,cAAc,UAAU,cAAc,MAAM;AAE1D,MAAI,YAAY,UAAU,GAAG;AAC3B,UAAM;AAAA,EACR,OAAO;AACL,UAAM,cAAc,KAAK,IAAI,GAAG,YAAY,IAAI,aAAW,QAAQ,KAAK,CAAC;AAEzE,QAAI,gBAAgB,YAAY,mBAAmB,QAAW;AAE5D;AAAA,IACF,OAAO;AACL,mBAAa,cAAc;AAC3B,iBAAW,YAAY,IAAI,cAAY,EAAE,OAAO,QAAQ,QAAQ,aAAa,MAAM,QAAQ,MAAM,IAAI,QAAQ,GAAG,EAAE;AAElH,iBAAW;AACX,uBAAiB,WAAW,WAAW,QAAQ;AAAA,IACjD;AAAA,EACF;AACF;AAEA,IAAM,YAAY,MAAM;AACtB,QAAM,YAAY,SAAS,OAAO,aAAW,QAAQ,QAAQ,QAAQ;AACrE,QAAM,SAAS,SAAS,OAAO,aAAW,QAAQ,SAAS,QAAQ;AAGnE,SAAO,WAAW,QAAQ;AAG1B,aAAW,WAAW,QAAQ;AAC5B,YAAQ,KAAK;AAAA,EACf;AACF;AAGO,IAAM,eAAe,CAAC,MAAgB,UAAkB;AAC7D,8BAAS,SAAS,GAAG,MAAM,oBAAoB;AAC/C,QAAM,KAAK,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,UAAa;AACzD,WAAS,KAAK,EAAE,OAAO,MAAM,GAAG,CAAC;AACjC,SAAO;AACP,SAAO;AACT;AAEO,IAAM,iBAAiB,CAAC,OAAe;AAC5C,aAAW,SAAS,OAAO,aAAW,QAAQ,OAAO,EAAE;AACvD,SAAO,QAAQ;AACjB;","names":[]}
|
package/dist/node/index.mjs
CHANGED
package/dist/node/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/setTimeoutEx.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/
|
|
1
|
+
{"version":3,"sources":["../../src/setTimeoutEx.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n func: Function\n id: string\n}\n\nlet timeouts: TimeoutInfo[] = []\nlet currentTimeout: NodeJS.Timeout | undefined\nlet interval = -1\n\nconst reset = () => {\n interval = -1\n clearTimeout(currentTimeout)\n currentTimeout = undefined\n timeouts = []\n}\n\nconst update = (newTimeouts = timeouts, delayPassed = 0) => {\n // if no more timeouts, set back to initial state\n if (newTimeouts.length <= 0) {\n reset()\n } else {\n const newInterval = Math.min(...newTimeouts.map(timeout => timeout.delay))\n\n if (newInterval === interval && currentTimeout !== undefined) {\n // since nothing changed, just return\n return\n } else {\n clearTimeout(currentTimeout)\n timeouts = newTimeouts.map(timeout => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }))\n // restart timeout since it needs to be different\n interval = newInterval\n currentTimeout = setTimeout(timerFunc, interval)\n }\n }\n}\n\nconst timerFunc = () => {\n const notFiring = timeouts.filter(timeout => timeout.delay > interval)\n const firing = timeouts.filter(timeout => timeout.delay <= interval)\n\n // call this after getting notFiring and firing since set will change in this call\n update(notFiring, interval)\n\n // trigger the ones that need to be triggered\n for (const timeout of firing) {\n timeout.func()\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const setTimeoutEx = (func: Function, delay: number) => {\n assertEx(delay >= 0, () => 'delay must be >= 0')\n const id = `${Date.now()}|${Math.random() * 9_999_999_999}`\n timeouts.push({ delay, func, id })\n update()\n return id\n}\n\nexport const clearTimeoutEx = (id: string) => {\n timeouts = timeouts.filter(timeout => timeout.id !== id)\n update(timeouts)\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AASzB,IAAI,WAA0B,CAAC;AAC/B,IAAI;AACJ,IAAI,WAAW;AAEf,IAAM,QAAQ,MAAM;AAClB,aAAW;AACX,eAAa,cAAc;AAC3B,mBAAiB;AACjB,aAAW,CAAC;AACd;AAEA,IAAM,SAAS,CAAC,cAAc,UAAU,cAAc,MAAM;AAE1D,MAAI,YAAY,UAAU,GAAG;AAC3B,UAAM;AAAA,EACR,OAAO;AACL,UAAM,cAAc,KAAK,IAAI,GAAG,YAAY,IAAI,aAAW,QAAQ,KAAK,CAAC;AAEzE,QAAI,gBAAgB,YAAY,mBAAmB,QAAW;AAE5D;AAAA,IACF,OAAO;AACL,mBAAa,cAAc;AAC3B,iBAAW,YAAY,IAAI,cAAY,EAAE,OAAO,QAAQ,QAAQ,aAAa,MAAM,QAAQ,MAAM,IAAI,QAAQ,GAAG,EAAE;AAElH,iBAAW;AACX,uBAAiB,WAAW,WAAW,QAAQ;AAAA,IACjD;AAAA,EACF;AACF;AAEA,IAAM,YAAY,MAAM;AACtB,QAAM,YAAY,SAAS,OAAO,aAAW,QAAQ,QAAQ,QAAQ;AACrE,QAAM,SAAS,SAAS,OAAO,aAAW,QAAQ,SAAS,QAAQ;AAGnE,SAAO,WAAW,QAAQ;AAG1B,aAAW,WAAW,QAAQ;AAC5B,YAAQ,KAAK;AAAA,EACf;AACF;AAGO,IAAM,eAAe,CAAC,MAAgB,UAAkB;AAC7D,WAAS,SAAS,GAAG,MAAM,oBAAoB;AAC/C,QAAM,KAAK,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,UAAa;AACzD,WAAS,KAAK,EAAE,OAAO,MAAM,GAAG,CAAC;AACjC,SAAO;AACP,SAAO;AACT;AAEO,IAAM,iBAAiB,CAAC,OAAe;AAC5C,aAAW,SAAS,OAAO,aAAW,QAAQ,OAAO,EAAE;AACvD,SAAO,QAAQ;AACjB;","names":[]}
|
package/package.json
CHANGED
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"types": "./dist/neutral/index.d.ts",
|
|
29
29
|
"module": "./dist/neutral/index.mjs",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@xylabs/assert": "^3.6.
|
|
31
|
+
"@xylabs/assert": "^3.6.9"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "^22.1.0",
|
|
35
|
-
"@xylabs/ts-scripts-yarn3": "^3.15.
|
|
36
|
-
"@xylabs/tsconfig": "^3.15.
|
|
35
|
+
"@xylabs/ts-scripts-yarn3": "^3.15.14",
|
|
36
|
+
"@xylabs/tsconfig": "^3.15.14",
|
|
37
37
|
"typescript": "^5.5.4"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
@@ -56,6 +56,6 @@
|
|
|
56
56
|
"url": "https://github.com/xylabs/sdk-js.git"
|
|
57
57
|
},
|
|
58
58
|
"sideEffects": false,
|
|
59
|
-
"version": "3.6.
|
|
59
|
+
"version": "3.6.9",
|
|
60
60
|
"type": "module"
|
|
61
61
|
}
|
package/src/setTimeoutEx.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { assertEx } from '@xylabs/assert'
|
|
|
2
2
|
|
|
3
3
|
interface TimeoutInfo {
|
|
4
4
|
delay: number
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
6
6
|
func: Function
|
|
7
7
|
id: string
|
|
8
8
|
}
|
|
@@ -12,26 +12,26 @@ let currentTimeout: NodeJS.Timeout | undefined
|
|
|
12
12
|
let interval = -1
|
|
13
13
|
|
|
14
14
|
const reset = () => {
|
|
15
|
-
interval -
|
|
15
|
+
interval = -1
|
|
16
16
|
clearTimeout(currentTimeout)
|
|
17
17
|
currentTimeout = undefined
|
|
18
18
|
timeouts = []
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const update = (newTimeouts = timeouts, delayPassed = 0) => {
|
|
22
|
-
//if no more timeouts, set back to initial state
|
|
22
|
+
// if no more timeouts, set back to initial state
|
|
23
23
|
if (newTimeouts.length <= 0) {
|
|
24
24
|
reset()
|
|
25
25
|
} else {
|
|
26
|
-
const newInterval = Math.min(...newTimeouts.map(
|
|
26
|
+
const newInterval = Math.min(...newTimeouts.map(timeout => timeout.delay))
|
|
27
27
|
|
|
28
28
|
if (newInterval === interval && currentTimeout !== undefined) {
|
|
29
|
-
//since nothing changed, just return
|
|
29
|
+
// since nothing changed, just return
|
|
30
30
|
return
|
|
31
31
|
} else {
|
|
32
32
|
clearTimeout(currentTimeout)
|
|
33
|
-
timeouts = newTimeouts.map(
|
|
34
|
-
//restart timeout since it needs to be different
|
|
33
|
+
timeouts = newTimeouts.map(timeout => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }))
|
|
34
|
+
// restart timeout since it needs to be different
|
|
35
35
|
interval = newInterval
|
|
36
36
|
currentTimeout = setTimeout(timerFunc, interval)
|
|
37
37
|
}
|
|
@@ -39,19 +39,19 @@ const update = (newTimeouts = timeouts, delayPassed = 0) => {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
const timerFunc = () => {
|
|
42
|
-
const notFiring = timeouts.filter(
|
|
43
|
-
const firing = timeouts.filter(
|
|
42
|
+
const notFiring = timeouts.filter(timeout => timeout.delay > interval)
|
|
43
|
+
const firing = timeouts.filter(timeout => timeout.delay <= interval)
|
|
44
44
|
|
|
45
|
-
//call this after getting notFiring and firing since set will change in this call
|
|
45
|
+
// call this after getting notFiring and firing since set will change in this call
|
|
46
46
|
update(notFiring, interval)
|
|
47
47
|
|
|
48
|
-
//trigger the ones that need to be triggered
|
|
48
|
+
// trigger the ones that need to be triggered
|
|
49
49
|
for (const timeout of firing) {
|
|
50
50
|
timeout.func()
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
55
55
|
export const setTimeoutEx = (func: Function, delay: number) => {
|
|
56
56
|
assertEx(delay >= 0, () => 'delay must be >= 0')
|
|
57
57
|
const id = `${Date.now()}|${Math.random() * 9_999_999_999}`
|
|
@@ -61,6 +61,6 @@ export const setTimeoutEx = (func: Function, delay: number) => {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export const clearTimeoutEx = (id: string) => {
|
|
64
|
-
timeouts = timeouts.filter(
|
|
64
|
+
timeouts = timeouts.filter(timeout => timeout.id !== id)
|
|
65
65
|
update(timeouts)
|
|
66
66
|
}
|