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.
- package/README.md +117 -36
- package/llms-full.txt +430 -0
- package/llms.txt +95 -0
- package/package.json +43 -12
- package/src/CancelTaskError.d.ts +2 -1
- package/src/CancelTaskError.js +2 -4
- package/src/Counter.d.ts +0 -1
- package/src/Counter.js +0 -2
- package/src/FrameQueue.d.ts +2 -2
- package/src/FrameQueue.js +0 -2
- package/src/IdleQueue.d.ts +2 -2
- package/src/IdleQueue.js +0 -2
- package/src/LimitedQueue.d.ts +104 -0
- package/src/LimitedQueue.js +78 -0
- package/src/ListQueue.d.ts +1 -6
- package/src/ListQueue.js +18 -3
- package/src/MicroTask.d.ts +7 -1
- package/src/MicroTask.js +47 -15
- package/src/MicroTaskQueue.d.ts +24 -20
- package/src/MicroTaskQueue.js +22 -7
- package/src/PageWatcher.d.ts +2 -2
- package/src/PageWatcher.js +0 -2
- package/src/Retainer.d.ts +4 -4
- package/src/Retainer.js +0 -2
- package/src/Scheduler.d.ts +23 -17
- package/src/Scheduler.js +1 -2
- package/src/Throttler.d.ts +7 -2
- package/src/Throttler.js +1 -2
- package/src/audit.js +0 -2
- package/src/batch.d.ts +16 -0
- package/src/batch.js +40 -0
- package/src/debounce.js +0 -2
- package/src/defer.d.ts +3 -4
- package/src/defer.js +0 -2
- package/src/index.d.ts +7 -2
- package/src/random-dist.d.ts +31 -0
- package/src/random-dist.js +27 -0
- package/src/random-sleep.d.ts +57 -0
- package/src/random-sleep.js +27 -0
- package/src/sample.d.ts +1 -1
- package/src/sample.js +0 -2
- package/src/sleep.d.ts +1 -1
- package/src/sleep.js +0 -2
- package/src/throttle.d.ts +2 -1
- package/src/throttle.js +0 -2
- package/src/when-dom-loaded.d.ts +4 -8
- package/src/when-dom-loaded.js +3 -9
- package/src/when-loaded.d.ts +4 -8
- 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
|
|
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
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
|
|
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
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,
|
|
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
package/src/when-dom-loaded.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
26
|
+
* Resolves a promise when the DOM is loaded.
|
|
29
27
|
*
|
|
30
|
-
* @param fn
|
|
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;
|
package/src/when-dom-loaded.js
CHANGED
|
@@ -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
|
|
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;
|
package/src/when-loaded.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
26
|
+
* Resolves a promise when the document is loaded.
|
|
29
27
|
*
|
|
30
|
-
* @param fn
|
|
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;
|
package/src/when-loaded.js
CHANGED
|
@@ -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
|
|
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;
|