time-queues 1.3.0 → 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.
package/src/audit.js CHANGED
@@ -1,7 +1,5 @@
1
1
  // @ts-self-types="./audit.d.ts"
2
2
 
3
- 'use strict';
4
-
5
3
  export const audit = (fn, ms) => {
6
4
  let handle = null,
7
5
  lastSeenArgs = null;
package/src/batch.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Runs asynchronous operations in parallel, no more than a specified number at a time.
3
3
  * It takes an array of functions, which return promises when invoked without arguments.
4
4
  * All other non-function values are passed as-is and promises are resolved.
5
- * Modelled after Promise.all().
5
+ * Modeled after Promise.all().
6
6
  *
7
7
  * @param fns An array of parameterless functions (asynchronous or not), promises, or values
8
8
  * @param limit How many asynchronous operations to run in parallel (default is 4)
package/src/batch.js CHANGED
@@ -1,7 +1,5 @@
1
1
  // @ts-self-types="./batch.d.ts"
2
2
 
3
- 'use strict';
4
-
5
3
  const wrap = value => {
6
4
  if (typeof value == 'function') return Promise.resolve(value());
7
5
  if (value && typeof value.then == 'function') return value; // thenable
@@ -9,6 +7,7 @@ const wrap = value => {
9
7
  };
10
8
 
11
9
  export const batch = (fns, limit = 4) => {
10
+ if (!fns.length) return Promise.resolve([]);
12
11
  if (limit < 1) limit = 1;
13
12
 
14
13
  const result = [];
package/src/debounce.js CHANGED
@@ -1,7 +1,5 @@
1
1
  // @ts-self-types="./debounce.d.ts"
2
2
 
3
- 'use strict';
4
-
5
3
  export const debounce = (fn, ms) => {
6
4
  let handle = null;
7
5
  return (...args) => {
package/src/defer.d.ts CHANGED
@@ -6,12 +6,11 @@
6
6
  * - `setTimeout()`
7
7
  *
8
8
  * @param fn The function to delay.
9
- * @returns A function that, when called, will execute the provided function.
10
9
  */
11
- export declare function defer<A extends unknown[]>(fn: (...args: A) => void): (...args: A) => void;
10
+ export declare function defer(fn: () => void): void;
12
11
 
13
12
  /**
14
- * Schedules a function to be called when the next available time.
13
+ * Schedules a function to be called at the next available time.
15
14
  *
16
15
  * @param fn The function to schedule.
17
16
  * @returns A promise that resolves when the function is called.
@@ -19,7 +18,7 @@ export declare function defer<A extends unknown[]>(fn: (...args: A) => void): (.
19
18
  export declare function scheduleDefer<R extends unknown>(fn: () => R): Promise<Awaited<R>>;
20
19
 
21
20
  /**
22
- * Schedules a function to be called when the next available time.
21
+ * Schedules a function to be called at the next available time.
23
22
  *
24
23
  * @param fn The function to schedule.
25
24
  * @returns A promise that resolves when the function is called.
package/src/defer.js CHANGED
@@ -1,7 +1,5 @@
1
1
  // @ts-self-types="./defer.d.ts"
2
2
 
3
- 'use strict';
4
-
5
3
  let deferImplementation = setTimeout;
6
4
 
7
5
  if (typeof requestIdleCallback == 'function') {
package/src/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  declare module 'time-queues' {
2
2
  export * from './audit';
3
+ export * from './batch';
3
4
  export * from './debounce';
4
5
  export * from './defer';
5
6
  export * from './sample';
@@ -9,15 +10,19 @@ declare module 'time-queues' {
9
10
  export * from './CancelTaskError';
10
11
  export * from './MicroTask';
11
12
  export * from './MicroTaskQueue';
13
+ export * from './LimitedQueue';
12
14
  export * from './ListQueue';
13
15
  export * from './FrameQueue';
14
16
  export * from './IdleQueue';
15
17
 
18
+ export * from './Counter';
16
19
  export * from './PageWatcher';
17
- export * from './Scheduler';
18
20
  export * from './Retainer';
21
+ export * from './Scheduler';
19
22
  export * from './Throttler';
20
- export * from './Counter';
23
+
24
+ export * from './random-dist';
25
+ export * from './random-sleep';
21
26
 
22
27
  export * from './when-dom-loaded';
23
28
  export * from './when-loaded';
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Random sleep function modelled after `sleep()`.
2
+ * Random sleep function modeled after `sleep()`.
3
3
  */
4
4
  export type RandomSleepFunction = () => Promise<void>;
5
5
 
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.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.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) => {
@@ -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();
@@ -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();