time-queues 1.2.4 → 1.3.1

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.
Files changed (49) hide show
  1. package/README.md +117 -36
  2. package/llms-full.txt +430 -0
  3. package/llms.txt +95 -0
  4. package/package.json +43 -12
  5. package/src/CancelTaskError.d.ts +2 -1
  6. package/src/CancelTaskError.js +2 -4
  7. package/src/Counter.d.ts +0 -1
  8. package/src/Counter.js +0 -2
  9. package/src/FrameQueue.d.ts +2 -2
  10. package/src/FrameQueue.js +0 -2
  11. package/src/IdleQueue.d.ts +2 -2
  12. package/src/IdleQueue.js +0 -2
  13. package/src/LimitedQueue.d.ts +104 -0
  14. package/src/LimitedQueue.js +78 -0
  15. package/src/ListQueue.d.ts +1 -6
  16. package/src/ListQueue.js +18 -3
  17. package/src/MicroTask.d.ts +7 -1
  18. package/src/MicroTask.js +47 -15
  19. package/src/MicroTaskQueue.d.ts +24 -20
  20. package/src/MicroTaskQueue.js +22 -7
  21. package/src/PageWatcher.d.ts +2 -2
  22. package/src/PageWatcher.js +0 -2
  23. package/src/Retainer.d.ts +4 -4
  24. package/src/Retainer.js +0 -2
  25. package/src/Scheduler.d.ts +23 -17
  26. package/src/Scheduler.js +1 -2
  27. package/src/Throttler.d.ts +7 -2
  28. package/src/Throttler.js +1 -2
  29. package/src/audit.js +0 -2
  30. package/src/batch.d.ts +16 -0
  31. package/src/batch.js +40 -0
  32. package/src/debounce.js +0 -2
  33. package/src/defer.d.ts +3 -4
  34. package/src/defer.js +0 -2
  35. package/src/index.d.ts +7 -2
  36. package/src/random-dist.d.ts +31 -0
  37. package/src/random-dist.js +27 -0
  38. package/src/random-sleep.d.ts +57 -0
  39. package/src/random-sleep.js +27 -0
  40. package/src/sample.d.ts +1 -1
  41. package/src/sample.js +0 -2
  42. package/src/sleep.d.ts +1 -1
  43. package/src/sleep.js +0 -2
  44. package/src/throttle.d.ts +2 -1
  45. package/src/throttle.js +0 -2
  46. package/src/when-dom-loaded.d.ts +4 -8
  47. package/src/when-dom-loaded.js +3 -9
  48. package/src/when-loaded.d.ts +4 -8
  49. package/src/when-loaded.js +3 -9
package/src/sample.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Samples a function by ensuring it is not called more often than the specified interval.
3
3
  * The last seen arguments are passed to the function after the specified time interval.
4
- * Unlike `audit()`, intervals are not reset by the function calls and never stops.
4
+ * Unlike `audit()`, intervals are not reset by the function calls and never stop.
5
5
  * If no call was made to the sampled function within the specified time interval,
6
6
  * no calls are made after the specified time interval.
7
7
  *
package/src/sample.js CHANGED
@@ -1,7 +1,5 @@
1
1
  // @ts-self-types="./sample.d.ts"
2
2
 
3
- 'use strict';
4
-
5
3
  export const sample = (fn, ms) => {
6
4
  const started = Date.now();
7
5
  let handle = null,
package/src/sleep.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Suspends the execution for a specified time.
3
3
  *
4
- * @param ms The time to suspend the execution for, in milliseconds or a date as an absolute time.
4
+ * @param ms The time to suspend the execution for, in milliseconds or a Date as an absolute time.
5
5
  * @returns A promise that resolves after the specified time.
6
6
  */
7
7
  export declare function sleep(ms: number | Date): Promise<void>;
package/src/sleep.js CHANGED
@@ -1,7 +1,5 @@
1
1
  // @ts-self-types="./sleep.d.ts"
2
2
 
3
- 'use strict';
4
-
5
3
  export const sleep = ms => {
6
4
  if (ms instanceof Date) {
7
5
  ms = ms.getTime() - Date.now();
package/src/throttle.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Throttles a function by ensuring it is not called more often than the specified interval.
3
- * The first call calls the function and starts a timeout. Until the timeout expires, any subsequent calls are ignored.
3
+ * The first call calls the function and starts a timeout. Until the timeout expires,
4
+ * any subsequent calls are ignored.
4
5
  * This function is similar to `audit()`, but the first seen arguments are passed to the function.
5
6
  *
6
7
  * @param fn The function to throttle.
package/src/throttle.js CHANGED
@@ -1,7 +1,5 @@
1
1
  // @ts-self-types="./throttle.d.ts"
2
2
 
3
- 'use strict';
4
-
5
3
  export const throttle = (fn, ms) => {
6
4
  let handle = null;
7
5
  return (...args) => {
@@ -20,18 +20,14 @@ export declare function remove(fn: () => void): boolean;
20
20
  * @param fn The function to schedule.
21
21
  * @returns A promise that resolves when the DOM is loaded.
22
22
  */
23
- export declare function scheduleWhenDomLoaded<R extends unknown>(
24
- fn: () => R
25
- ): Promise<Awaited<R>>;
23
+ export declare function scheduleWhenDomLoaded<R extends unknown>(fn: () => R): Promise<Awaited<R>>;
26
24
 
27
25
  /**
28
- * Schedules a function to be called when the DOM is loaded.
26
+ * Resolves a promise when the DOM is loaded.
29
27
  *
30
- * @param fn The function to schedule.
28
+ * @param fn `null` or `undefined`.
31
29
  * @returns A promise that resolves when the DOM is loaded.
32
30
  */
33
- export declare function scheduleWhenDomLoaded(
34
- fn: null | undefined
35
- ): Promise<void>;
31
+ export declare function scheduleWhenDomLoaded(fn?: null): Promise<void>;
36
32
 
37
33
  export default whenDomLoaded;
@@ -1,7 +1,5 @@
1
1
  // @ts-self-types="./when-dom-loaded.d.ts"
2
2
 
3
- 'use strict';
4
-
5
3
  import ValueList from 'list-toolkit/value-list.js';
6
4
 
7
5
  const waitingForDom = new ValueList();
@@ -34,19 +32,15 @@ export const whenDomLoaded = fn => {
34
32
  if (wasEmpty) document.addEventListener('DOMContentLoaded', handleDomLoaded);
35
33
  };
36
34
 
37
- const returnArgs = (...args) => args;
38
-
39
- export const scheduleWhenDomLoaded = fn => {
40
- fn ||= returnArgs;
41
- return new Promise((resolve, reject) => {
35
+ export const scheduleWhenDomLoaded = fn =>
36
+ new Promise((resolve, reject) => {
42
37
  whenDomLoaded(() => {
43
38
  try {
44
- resolve(fn());
39
+ resolve(fn?.());
45
40
  } catch (error) {
46
41
  reject(error);
47
42
  }
48
43
  });
49
44
  });
50
- };
51
45
 
52
46
  export default whenDomLoaded;
@@ -20,18 +20,14 @@ export declare function remove(fn: () => void): boolean;
20
20
  * @param fn The function to schedule.
21
21
  * @returns A promise that resolves when the document is loaded.
22
22
  */
23
- export declare function scheduleWhenLoaded<R extends unknown>(
24
- fn: () => R
25
- ): Promise<Awaited<R>>;
23
+ export declare function scheduleWhenLoaded<R extends unknown>(fn: () => R): Promise<Awaited<R>>;
26
24
 
27
25
  /**
28
- * Schedules a function to be called when the document is loaded.
26
+ * Resolves a promise when the document is loaded.
29
27
  *
30
- * @param fn The function to schedule.
28
+ * @param fn `null` or `undefined`.
31
29
  * @returns A promise that resolves when the document is loaded.
32
30
  */
33
- export declare function scheduleWhenLoaded(
34
- fn: null | undefined
35
- ): Promise<void>;
31
+ export declare function scheduleWhenLoaded(fn?: null): Promise<void>;
36
32
 
37
33
  export default whenLoaded;
@@ -1,7 +1,5 @@
1
1
  // @ts-self-types="./when-loaded.d.ts"
2
2
 
3
- 'use strict';
4
-
5
3
  import ValueList from 'list-toolkit/value-list.js';
6
4
 
7
5
  const waitingForLoad = new ValueList();
@@ -32,19 +30,15 @@ export const whenLoaded = fn => {
32
30
  if (wasEmpty) window.addEventListener('load', handleLoaded);
33
31
  };
34
32
 
35
- const returnArgs = (...args) => args;
36
-
37
- export const scheduleWhenLoaded = fn => {
38
- fn ||= returnArgs;
39
- return new Promise((resolve, reject) => {
33
+ export const scheduleWhenLoaded = fn =>
34
+ new Promise((resolve, reject) => {
40
35
  whenLoaded(() => {
41
36
  try {
42
- resolve(fn());
37
+ resolve(fn?.());
43
38
  } catch (error) {
44
39
  reject(error);
45
40
  }
46
41
  });
47
42
  });
48
- };
49
43
 
50
44
  export default whenLoaded;