@tanstack/query-async-storage-persister 5.85.9 → 5.87.0

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.
@@ -23,6 +23,7 @@ __export(asyncThrottle_exports, {
23
23
  asyncThrottle: () => asyncThrottle
24
24
  });
25
25
  module.exports = __toCommonJS(asyncThrottle_exports);
26
+ var import_query_core = require("@tanstack/query-core");
26
27
  var import_utils = require("./utils.cjs");
27
28
  function asyncThrottle(func, { interval = 1e3, onError = import_utils.noop } = {}) {
28
29
  if (typeof func !== "function") throw new Error("argument is not function.");
@@ -35,11 +36,11 @@ function asyncThrottle(func, { interval = 1e3, onError = import_utils.noop } = {
35
36
  if (isScheduled) return;
36
37
  isScheduled = true;
37
38
  while (isExecuting) {
38
- await new Promise((done) => setTimeout(done, interval));
39
+ await new Promise((done) => import_query_core.timeoutManager.setTimeout(done, interval));
39
40
  }
40
41
  while (Date.now() < nextExecutionTime) {
41
42
  await new Promise(
42
- (done) => setTimeout(done, nextExecutionTime - Date.now())
43
+ (done) => import_query_core.timeoutManager.setTimeout(done, nextExecutionTime - Date.now())
43
44
  );
44
45
  }
45
46
  isScheduled = false;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["import { noop } from './utils'\n\ninterface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let nextExecutionTime = 0\n let lastArgs = null\n let isExecuting = false\n let isScheduled = false\n\n return async (...args: TArgs) => {\n lastArgs = args\n if (isScheduled) return\n isScheduled = true\n while (isExecuting) {\n await new Promise((done) => setTimeout(done, interval))\n }\n while (Date.now() < nextExecutionTime) {\n await new Promise((done) =>\n setTimeout(done, nextExecutionTime - Date.now()),\n )\n }\n isScheduled = false\n isExecuting = true\n try {\n await func(...lastArgs)\n } catch (error) {\n try {\n onError(error)\n } catch {}\n }\n nextExecutionTime = Date.now() + interval\n isExecuting = false\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqB;AAOd,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,kBAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS,WAAY,OAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,oBAAoB;AACxB,MAAI,WAAW;AACf,MAAI,cAAc;AAClB,MAAI,cAAc;AAElB,SAAO,UAAU,SAAgB;AAC/B,eAAW;AACX,QAAI,YAAa;AACjB,kBAAc;AACd,WAAO,aAAa;AAClB,YAAM,IAAI,QAAQ,CAAC,SAAS,WAAW,MAAM,QAAQ,CAAC;AAAA,IACxD;AACA,WAAO,KAAK,IAAI,IAAI,mBAAmB;AACrC,YAAM,IAAI;AAAA,QAAQ,CAAC,SACjB,WAAW,MAAM,oBAAoB,KAAK,IAAI,CAAC;AAAA,MACjD;AAAA,IACF;AACA,kBAAc;AACd,kBAAc;AACd,QAAI;AACF,YAAM,KAAK,GAAG,QAAQ;AAAA,IACxB,SAAS,OAAO;AACd,UAAI;AACF,gBAAQ,KAAK;AAAA,MACf,QAAQ;AAAA,MAAC;AAAA,IACX;AACA,wBAAoB,KAAK,IAAI,IAAI;AACjC,kBAAc;AAAA,EAChB;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\n\ninterface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let nextExecutionTime = 0\n let lastArgs = null\n let isExecuting = false\n let isScheduled = false\n\n return async (...args: TArgs) => {\n lastArgs = args\n if (isScheduled) return\n isScheduled = true\n while (isExecuting) {\n await new Promise((done) => timeoutManager.setTimeout(done, interval))\n }\n while (Date.now() < nextExecutionTime) {\n await new Promise((done) =>\n timeoutManager.setTimeout(done, nextExecutionTime - Date.now()),\n )\n }\n isScheduled = false\n isExecuting = true\n try {\n await func(...lastArgs)\n } catch (error) {\n try {\n onError(error)\n } catch {}\n }\n nextExecutionTime = Date.now() + interval\n isExecuting = false\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA+B;AAC/B,mBAAqB;AAOd,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,kBAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS,WAAY,OAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,oBAAoB;AACxB,MAAI,WAAW;AACf,MAAI,cAAc;AAClB,MAAI,cAAc;AAElB,SAAO,UAAU,SAAgB;AAC/B,eAAW;AACX,QAAI,YAAa;AACjB,kBAAc;AACd,WAAO,aAAa;AAClB,YAAM,IAAI,QAAQ,CAAC,SAAS,iCAAe,WAAW,MAAM,QAAQ,CAAC;AAAA,IACvE;AACA,WAAO,KAAK,IAAI,IAAI,mBAAmB;AACrC,YAAM,IAAI;AAAA,QAAQ,CAAC,SACjB,iCAAe,WAAW,MAAM,oBAAoB,KAAK,IAAI,CAAC;AAAA,MAChE;AAAA,IACF;AACA,kBAAc;AACd,kBAAc;AACd,QAAI;AACF,YAAM,KAAK,GAAG,QAAQ;AAAA,IACxB,SAAS,OAAO;AACd,UAAI;AACF,gBAAQ,KAAK;AAAA,MACf,QAAQ;AAAA,MAAC;AAAA,IACX;AACA,wBAAoB,KAAK,IAAI,IAAI;AACjC,kBAAc;AAAA,EAChB;AACF;","names":[]}
@@ -1,4 +1,5 @@
1
1
  // src/asyncThrottle.ts
2
+ import { timeoutManager } from "@tanstack/query-core";
2
3
  import { noop } from "./utils.js";
3
4
  function asyncThrottle(func, { interval = 1e3, onError = noop } = {}) {
4
5
  if (typeof func !== "function") throw new Error("argument is not function.");
@@ -11,11 +12,11 @@ function asyncThrottle(func, { interval = 1e3, onError = noop } = {}) {
11
12
  if (isScheduled) return;
12
13
  isScheduled = true;
13
14
  while (isExecuting) {
14
- await new Promise((done) => setTimeout(done, interval));
15
+ await new Promise((done) => timeoutManager.setTimeout(done, interval));
15
16
  }
16
17
  while (Date.now() < nextExecutionTime) {
17
18
  await new Promise(
18
- (done) => setTimeout(done, nextExecutionTime - Date.now())
19
+ (done) => timeoutManager.setTimeout(done, nextExecutionTime - Date.now())
19
20
  );
20
21
  }
21
22
  isScheduled = false;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["import { noop } from './utils'\n\ninterface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let nextExecutionTime = 0\n let lastArgs = null\n let isExecuting = false\n let isScheduled = false\n\n return async (...args: TArgs) => {\n lastArgs = args\n if (isScheduled) return\n isScheduled = true\n while (isExecuting) {\n await new Promise((done) => setTimeout(done, interval))\n }\n while (Date.now() < nextExecutionTime) {\n await new Promise((done) =>\n setTimeout(done, nextExecutionTime - Date.now()),\n )\n }\n isScheduled = false\n isExecuting = true\n try {\n await func(...lastArgs)\n } catch (error) {\n try {\n onError(error)\n } catch {}\n }\n nextExecutionTime = Date.now() + interval\n isExecuting = false\n }\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,KAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS,WAAY,OAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,oBAAoB;AACxB,MAAI,WAAW;AACf,MAAI,cAAc;AAClB,MAAI,cAAc;AAElB,SAAO,UAAU,SAAgB;AAC/B,eAAW;AACX,QAAI,YAAa;AACjB,kBAAc;AACd,WAAO,aAAa;AAClB,YAAM,IAAI,QAAQ,CAAC,SAAS,WAAW,MAAM,QAAQ,CAAC;AAAA,IACxD;AACA,WAAO,KAAK,IAAI,IAAI,mBAAmB;AACrC,YAAM,IAAI;AAAA,QAAQ,CAAC,SACjB,WAAW,MAAM,oBAAoB,KAAK,IAAI,CAAC;AAAA,MACjD;AAAA,IACF;AACA,kBAAc;AACd,kBAAc;AACd,QAAI;AACF,YAAM,KAAK,GAAG,QAAQ;AAAA,IACxB,SAAS,OAAO;AACd,UAAI;AACF,gBAAQ,KAAK;AAAA,MACf,QAAQ;AAAA,MAAC;AAAA,IACX;AACA,wBAAoB,KAAK,IAAI,IAAI;AACjC,kBAAc;AAAA,EAChB;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\n\ninterface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let nextExecutionTime = 0\n let lastArgs = null\n let isExecuting = false\n let isScheduled = false\n\n return async (...args: TArgs) => {\n lastArgs = args\n if (isScheduled) return\n isScheduled = true\n while (isExecuting) {\n await new Promise((done) => timeoutManager.setTimeout(done, interval))\n }\n while (Date.now() < nextExecutionTime) {\n await new Promise((done) =>\n timeoutManager.setTimeout(done, nextExecutionTime - Date.now()),\n )\n }\n isScheduled = false\n isExecuting = true\n try {\n await func(...lastArgs)\n } catch (error) {\n try {\n onError(error)\n } catch {}\n }\n nextExecutionTime = Date.now() + interval\n isExecuting = false\n }\n}\n"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AAOd,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,KAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS,WAAY,OAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,oBAAoB;AACxB,MAAI,WAAW;AACf,MAAI,cAAc;AAClB,MAAI,cAAc;AAElB,SAAO,UAAU,SAAgB;AAC/B,eAAW;AACX,QAAI,YAAa;AACjB,kBAAc;AACd,WAAO,aAAa;AAClB,YAAM,IAAI,QAAQ,CAAC,SAAS,eAAe,WAAW,MAAM,QAAQ,CAAC;AAAA,IACvE;AACA,WAAO,KAAK,IAAI,IAAI,mBAAmB;AACrC,YAAM,IAAI;AAAA,QAAQ,CAAC,SACjB,eAAe,WAAW,MAAM,oBAAoB,KAAK,IAAI,CAAC;AAAA,MAChE;AAAA,IACF;AACA,kBAAc;AACd,kBAAc;AACd,QAAI;AACF,YAAM,KAAK,GAAG,QAAQ;AAAA,IACxB,SAAS,OAAO;AACd,UAAI;AACF,gBAAQ,KAAK;AAAA,MACf,QAAQ;AAAA,MAAC;AAAA,IACX;AACA,wBAAoB,KAAK,IAAI,IAAI;AACjC,kBAAc;AAAA,EAChB;AACF;","names":[]}
@@ -23,6 +23,7 @@ __export(asyncThrottle_exports, {
23
23
  asyncThrottle: () => asyncThrottle
24
24
  });
25
25
  module.exports = __toCommonJS(asyncThrottle_exports);
26
+ var import_query_core = require("@tanstack/query-core");
26
27
  var import_utils = require("./utils.cjs");
27
28
  function asyncThrottle(func, { interval = 1e3, onError = import_utils.noop } = {}) {
28
29
  if (typeof func !== "function") throw new Error("argument is not function.");
@@ -35,11 +36,11 @@ function asyncThrottle(func, { interval = 1e3, onError = import_utils.noop } = {
35
36
  if (isScheduled) return;
36
37
  isScheduled = true;
37
38
  while (isExecuting) {
38
- await new Promise((done) => setTimeout(done, interval));
39
+ await new Promise((done) => import_query_core.timeoutManager.setTimeout(done, interval));
39
40
  }
40
41
  while (Date.now() < nextExecutionTime) {
41
42
  await new Promise(
42
- (done) => setTimeout(done, nextExecutionTime - Date.now())
43
+ (done) => import_query_core.timeoutManager.setTimeout(done, nextExecutionTime - Date.now())
43
44
  );
44
45
  }
45
46
  isScheduled = false;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["import { noop } from './utils'\n\ninterface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let nextExecutionTime = 0\n let lastArgs = null\n let isExecuting = false\n let isScheduled = false\n\n return async (...args: TArgs) => {\n lastArgs = args\n if (isScheduled) return\n isScheduled = true\n while (isExecuting) {\n await new Promise((done) => setTimeout(done, interval))\n }\n while (Date.now() < nextExecutionTime) {\n await new Promise((done) =>\n setTimeout(done, nextExecutionTime - Date.now()),\n )\n }\n isScheduled = false\n isExecuting = true\n try {\n await func(...lastArgs)\n } catch (error) {\n try {\n onError(error)\n } catch {}\n }\n nextExecutionTime = Date.now() + interval\n isExecuting = false\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqB;AAOd,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,kBAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS,WAAY,OAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,oBAAoB;AACxB,MAAI,WAAW;AACf,MAAI,cAAc;AAClB,MAAI,cAAc;AAElB,SAAO,UAAU,SAAgB;AAC/B,eAAW;AACX,QAAI,YAAa;AACjB,kBAAc;AACd,WAAO,aAAa;AAClB,YAAM,IAAI,QAAQ,CAAC,SAAS,WAAW,MAAM,QAAQ,CAAC;AAAA,IACxD;AACA,WAAO,KAAK,IAAI,IAAI,mBAAmB;AACrC,YAAM,IAAI;AAAA,QAAQ,CAAC,SACjB,WAAW,MAAM,oBAAoB,KAAK,IAAI,CAAC;AAAA,MACjD;AAAA,IACF;AACA,kBAAc;AACd,kBAAc;AACd,QAAI;AACF,YAAM,KAAK,GAAG,QAAQ;AAAA,IACxB,SAAS,OAAO;AACd,UAAI;AACF,gBAAQ,KAAK;AAAA,MACf,QAAQ;AAAA,MAAC;AAAA,IACX;AACA,wBAAoB,KAAK,IAAI,IAAI;AACjC,kBAAc;AAAA,EAChB;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\n\ninterface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let nextExecutionTime = 0\n let lastArgs = null\n let isExecuting = false\n let isScheduled = false\n\n return async (...args: TArgs) => {\n lastArgs = args\n if (isScheduled) return\n isScheduled = true\n while (isExecuting) {\n await new Promise((done) => timeoutManager.setTimeout(done, interval))\n }\n while (Date.now() < nextExecutionTime) {\n await new Promise((done) =>\n timeoutManager.setTimeout(done, nextExecutionTime - Date.now()),\n )\n }\n isScheduled = false\n isExecuting = true\n try {\n await func(...lastArgs)\n } catch (error) {\n try {\n onError(error)\n } catch {}\n }\n nextExecutionTime = Date.now() + interval\n isExecuting = false\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA+B;AAC/B,mBAAqB;AAOd,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,kBAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS,WAAY,OAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,oBAAoB;AACxB,MAAI,WAAW;AACf,MAAI,cAAc;AAClB,MAAI,cAAc;AAElB,SAAO,UAAU,SAAgB;AAC/B,eAAW;AACX,QAAI,YAAa;AACjB,kBAAc;AACd,WAAO,aAAa;AAClB,YAAM,IAAI,QAAQ,CAAC,SAAS,iCAAe,WAAW,MAAM,QAAQ,CAAC;AAAA,IACvE;AACA,WAAO,KAAK,IAAI,IAAI,mBAAmB;AACrC,YAAM,IAAI;AAAA,QAAQ,CAAC,SACjB,iCAAe,WAAW,MAAM,oBAAoB,KAAK,IAAI,CAAC;AAAA,MAChE;AAAA,IACF;AACA,kBAAc;AACd,kBAAc;AACd,QAAI;AACF,YAAM,KAAK,GAAG,QAAQ;AAAA,IACxB,SAAS,OAAO;AACd,UAAI;AACF,gBAAQ,KAAK;AAAA,MACf,QAAQ;AAAA,MAAC;AAAA,IACX;AACA,wBAAoB,KAAK,IAAI,IAAI;AACjC,kBAAc;AAAA,EAChB;AACF;","names":[]}
@@ -1,4 +1,5 @@
1
1
  // src/asyncThrottle.ts
2
+ import { timeoutManager } from "@tanstack/query-core";
2
3
  import { noop } from "./utils.js";
3
4
  function asyncThrottle(func, { interval = 1e3, onError = noop } = {}) {
4
5
  if (typeof func !== "function") throw new Error("argument is not function.");
@@ -11,11 +12,11 @@ function asyncThrottle(func, { interval = 1e3, onError = noop } = {}) {
11
12
  if (isScheduled) return;
12
13
  isScheduled = true;
13
14
  while (isExecuting) {
14
- await new Promise((done) => setTimeout(done, interval));
15
+ await new Promise((done) => timeoutManager.setTimeout(done, interval));
15
16
  }
16
17
  while (Date.now() < nextExecutionTime) {
17
18
  await new Promise(
18
- (done) => setTimeout(done, nextExecutionTime - Date.now())
19
+ (done) => timeoutManager.setTimeout(done, nextExecutionTime - Date.now())
19
20
  );
20
21
  }
21
22
  isScheduled = false;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["import { noop } from './utils'\n\ninterface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let nextExecutionTime = 0\n let lastArgs = null\n let isExecuting = false\n let isScheduled = false\n\n return async (...args: TArgs) => {\n lastArgs = args\n if (isScheduled) return\n isScheduled = true\n while (isExecuting) {\n await new Promise((done) => setTimeout(done, interval))\n }\n while (Date.now() < nextExecutionTime) {\n await new Promise((done) =>\n setTimeout(done, nextExecutionTime - Date.now()),\n )\n }\n isScheduled = false\n isExecuting = true\n try {\n await func(...lastArgs)\n } catch (error) {\n try {\n onError(error)\n } catch {}\n }\n nextExecutionTime = Date.now() + interval\n isExecuting = false\n }\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,KAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS,WAAY,OAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,oBAAoB;AACxB,MAAI,WAAW;AACf,MAAI,cAAc;AAClB,MAAI,cAAc;AAElB,SAAO,UAAU,SAAgB;AAC/B,eAAW;AACX,QAAI,YAAa;AACjB,kBAAc;AACd,WAAO,aAAa;AAClB,YAAM,IAAI,QAAQ,CAAC,SAAS,WAAW,MAAM,QAAQ,CAAC;AAAA,IACxD;AACA,WAAO,KAAK,IAAI,IAAI,mBAAmB;AACrC,YAAM,IAAI;AAAA,QAAQ,CAAC,SACjB,WAAW,MAAM,oBAAoB,KAAK,IAAI,CAAC;AAAA,MACjD;AAAA,IACF;AACA,kBAAc;AACd,kBAAc;AACd,QAAI;AACF,YAAM,KAAK,GAAG,QAAQ;AAAA,IACxB,SAAS,OAAO;AACd,UAAI;AACF,gBAAQ,KAAK;AAAA,MACf,QAAQ;AAAA,MAAC;AAAA,IACX;AACA,wBAAoB,KAAK,IAAI,IAAI;AACjC,kBAAc;AAAA,EAChB;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\n\ninterface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let nextExecutionTime = 0\n let lastArgs = null\n let isExecuting = false\n let isScheduled = false\n\n return async (...args: TArgs) => {\n lastArgs = args\n if (isScheduled) return\n isScheduled = true\n while (isExecuting) {\n await new Promise((done) => timeoutManager.setTimeout(done, interval))\n }\n while (Date.now() < nextExecutionTime) {\n await new Promise((done) =>\n timeoutManager.setTimeout(done, nextExecutionTime - Date.now()),\n )\n }\n isScheduled = false\n isExecuting = true\n try {\n await func(...lastArgs)\n } catch (error) {\n try {\n onError(error)\n } catch {}\n }\n nextExecutionTime = Date.now() + interval\n isExecuting = false\n }\n}\n"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AAOd,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,KAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS,WAAY,OAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,oBAAoB;AACxB,MAAI,WAAW;AACf,MAAI,cAAc;AAClB,MAAI,cAAc;AAElB,SAAO,UAAU,SAAgB;AAC/B,eAAW;AACX,QAAI,YAAa;AACjB,kBAAc;AACd,WAAO,aAAa;AAClB,YAAM,IAAI,QAAQ,CAAC,SAAS,eAAe,WAAW,MAAM,QAAQ,CAAC;AAAA,IACvE;AACA,WAAO,KAAK,IAAI,IAAI,mBAAmB;AACrC,YAAM,IAAI;AAAA,QAAQ,CAAC,SACjB,eAAe,WAAW,MAAM,oBAAoB,KAAK,IAAI,CAAC;AAAA,MAChE;AAAA,IACF;AACA,kBAAc;AACd,kBAAc;AACd,QAAI;AACF,YAAM,KAAK,GAAG,QAAQ;AAAA,IACxB,SAAS,OAAO;AACd,UAAI;AACF,gBAAQ,KAAK;AAAA,MACf,QAAQ;AAAA,MAAC;AAAA,IACX;AACA,wBAAoB,KAAK,IAAI,IAAI;AACjC,kBAAc;AAAA,EAChB;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-async-storage-persister",
3
- "version": "5.85.9",
3
+ "version": "5.87.0",
4
4
  "description": "A persister for asynchronous storages, to be used with TanStack/Query",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -40,7 +40,8 @@
40
40
  "!src/__tests__"
41
41
  ],
42
42
  "dependencies": {
43
- "@tanstack/query-persist-client-core": "5.85.9"
43
+ "@tanstack/query-core": "5.87.0",
44
+ "@tanstack/query-persist-client-core": "5.87.0"
44
45
  },
45
46
  "devDependencies": {
46
47
  "npm-run-all2": "^5.0.0",
@@ -1,3 +1,4 @@
1
+ import { timeoutManager } from '@tanstack/query-core'
1
2
  import { noop } from './utils'
2
3
 
3
4
  interface AsyncThrottleOptions {
@@ -21,11 +22,11 @@ export function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(
21
22
  if (isScheduled) return
22
23
  isScheduled = true
23
24
  while (isExecuting) {
24
- await new Promise((done) => setTimeout(done, interval))
25
+ await new Promise((done) => timeoutManager.setTimeout(done, interval))
25
26
  }
26
27
  while (Date.now() < nextExecutionTime) {
27
28
  await new Promise((done) =>
28
- setTimeout(done, nextExecutionTime - Date.now()),
29
+ timeoutManager.setTimeout(done, nextExecutionTime - Date.now()),
29
30
  )
30
31
  }
31
32
  isScheduled = false