time-queues 1.1.0 → 1.1.2
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 +3 -1
- package/package.json +7 -4
- package/src/FrameQueue.d.ts +6 -1
- package/src/IdleQueue.d.ts +6 -1
- package/src/ListQueue.d.ts +3 -3
- package/src/MicroTaskQueue.d.ts +1 -1
- package/src/PageWatcher.d.ts +6 -1
- package/src/Retainer.d.ts +29 -8
- package/src/Scheduler.d.ts +27 -2
- package/src/Throttler.d.ts +19 -3
- package/src/audit.d.ts +3 -3
- package/src/debounce.d.ts +3 -3
- package/src/index.d.ts +22 -0
- package/src/sample.d.ts +3 -3
- package/src/throttle.d.ts +3 -3
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ npm install
|
|
|
32
32
|
|
|
33
33
|
## Usage
|
|
34
34
|
|
|
35
|
-
The full documentation is available in the project's [wiki](https://github.com/uhop/time-queues/wiki). Below is the most important parts of the documentation:
|
|
35
|
+
The full documentation is available in the project's [wiki](https://github.com/uhop/time-queues/wiki). Below is a summary of the most important parts of the documentation:
|
|
36
36
|
|
|
37
37
|
### Resource Management
|
|
38
38
|
|
|
@@ -61,6 +61,8 @@ This project is licensed under the BSD-3-Clause License.
|
|
|
61
61
|
|
|
62
62
|
## Release History
|
|
63
63
|
|
|
64
|
+
* 1.1.2 *Updated dev dependencies. No need to upgrade.*
|
|
65
|
+
* 1.1.1 *Updates to TS typings.*
|
|
64
66
|
* 1.1.0 *Added `Throttler`, `Retainer`, promise-based convenience time methods.*
|
|
65
67
|
* 1.0.5 *Technical release: updated deps, more tests.*
|
|
66
68
|
* 1.0.4 *Bug fixes and code simplifications.*
|
package/package.json
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "time-queues",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Time queues to organize multitasking and scheduled tasks.",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
6
7
|
"exports": {
|
|
7
8
|
"./*": "./src/*"
|
|
8
9
|
},
|
|
9
10
|
"scripts": {
|
|
10
11
|
"test": "tape6 --flags FO",
|
|
11
12
|
"test:bun": "tape6-bun --flags FO",
|
|
12
|
-
"test:deno
|
|
13
|
-
"test:deno": "deno run -A `tape6-runner main` --flags FO",
|
|
13
|
+
"test:deno": "tape6-deno --flags FO",
|
|
14
14
|
"test:proc": "tape6-proc --flags FO",
|
|
15
15
|
"test:proc:bun": "bun run `npx tape6-proc --self` --flags FO",
|
|
16
16
|
"test:proc:deno": "deno run -A `npx tape6-proc --self` --flags FO --runFileArgs -A",
|
|
17
17
|
"ts-check": "tsc --noEmit",
|
|
18
|
+
"ts-test": "tape6 --flags FO '/ts-tests/test-*.*ts'",
|
|
19
|
+
"ts-test:bun": "tape6-bun --flags FO '/ts-tests/test-*.*ts'",
|
|
20
|
+
"ts-test:deno": "tape6-deno --flags FO '/ts-tests/test-*.*ts'",
|
|
18
21
|
"lint": "prettier --check src/ tests/ wiki/",
|
|
19
22
|
"lint:fix": "prettier --write src/ tests/ wiki/",
|
|
20
23
|
"start": "tape6-server --trace"
|
|
@@ -54,7 +57,7 @@
|
|
|
54
57
|
},
|
|
55
58
|
"devDependencies": {
|
|
56
59
|
"@types/node": "^22.13.10",
|
|
57
|
-
"tape-six": "^1.
|
|
60
|
+
"tape-six": "^1.1.1",
|
|
58
61
|
"tape-six-proc": "^1.0.1",
|
|
59
62
|
"typescript": "^5.8.2"
|
|
60
63
|
},
|
package/src/FrameQueue.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ import {ListQueue, Task} from './ListQueue';
|
|
|
5
5
|
* Used in an animation loop or for drawing updates.
|
|
6
6
|
*/
|
|
7
7
|
export declare class FrameQueue extends ListQueue {
|
|
8
|
+
/**
|
|
9
|
+
* Whether the queue is paused.
|
|
10
|
+
*/
|
|
11
|
+
paused: boolean;
|
|
12
|
+
|
|
8
13
|
/**
|
|
9
14
|
* The batch size in milliseconds for running tasks.
|
|
10
15
|
* If `undefined`, all tasks are run in a single frame.
|
|
@@ -16,7 +21,7 @@ export declare class FrameQueue extends ListQueue {
|
|
|
16
21
|
* @param paused Whether the queue should start paused.
|
|
17
22
|
* @param batchInMs The batch size in milliseconds.
|
|
18
23
|
*/
|
|
19
|
-
constructor(paused
|
|
24
|
+
constructor(paused?: boolean, batchInMs?: number);
|
|
20
25
|
|
|
21
26
|
/**
|
|
22
27
|
* Whether the queue is empty.
|
package/src/IdleQueue.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ import {ListQueue, Task} from './ListQueue';
|
|
|
5
5
|
* Used for background tasks.
|
|
6
6
|
*/
|
|
7
7
|
export declare class IdleQueue extends ListQueue {
|
|
8
|
+
/**
|
|
9
|
+
* Whether the queue is paused.
|
|
10
|
+
*/
|
|
11
|
+
paused: boolean;
|
|
12
|
+
|
|
8
13
|
/**
|
|
9
14
|
* The timeout batch size in milliseconds for running tasks.
|
|
10
15
|
* If `undefined`, all tasks are run in a single idle period.
|
|
@@ -23,7 +28,7 @@ export declare class IdleQueue extends ListQueue {
|
|
|
23
28
|
* @param timeoutBatchInMs The timeout batch size in milliseconds.
|
|
24
29
|
* @param options The options passed to `requestIdleCallback()`.
|
|
25
30
|
*/
|
|
26
|
-
constructor(paused
|
|
31
|
+
constructor(paused?: boolean, timeoutBatchInMs?: number, options?: IdleCallbackOptions);
|
|
27
32
|
|
|
28
33
|
/**
|
|
29
34
|
* Whether the queue is empty.
|
package/src/ListQueue.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ import {List} from 'list-toolkit';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class ListQueue extends MicroTaskQueue {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Whether the queue is paused.
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
paused: boolean;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* The function that stops the queue.
|
|
@@ -21,7 +21,7 @@ export declare class ListQueue extends MicroTaskQueue {
|
|
|
21
21
|
* Creates a new list queue.
|
|
22
22
|
* @param paused Whether the queue should start paused.
|
|
23
23
|
*/
|
|
24
|
-
constructor(paused
|
|
24
|
+
constructor(paused?: boolean);
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Whether the queue is empty.
|
package/src/MicroTaskQueue.d.ts
CHANGED
package/src/PageWatcher.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ export declare type PageState = 'active' | 'passive' | 'hidden' | 'frozen' | 'te
|
|
|
9
9
|
* A queue that monitors the page's lifecycle.
|
|
10
10
|
*/
|
|
11
11
|
export declare class PageWatcher extends ListQueue {
|
|
12
|
+
/**
|
|
13
|
+
* Whether the queue is paused.
|
|
14
|
+
*/
|
|
15
|
+
paused: boolean;
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
18
|
* The current state of the page.
|
|
14
19
|
*/
|
|
@@ -18,7 +23,7 @@ export declare class PageWatcher extends ListQueue {
|
|
|
18
23
|
* Creates a new page watcher.
|
|
19
24
|
* @param started Whether the queue is unpaused initially.
|
|
20
25
|
*/
|
|
21
|
-
constructor(started
|
|
26
|
+
constructor(started?: boolean);
|
|
22
27
|
|
|
23
28
|
/**
|
|
24
29
|
* Whether the queue is empty.
|
package/src/Retainer.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The options for a retainer.
|
|
3
3
|
*/
|
|
4
|
-
export declare interface RetainerOptions {
|
|
4
|
+
export declare interface RetainerOptions<T = unknown> {
|
|
5
5
|
/**
|
|
6
6
|
* The function to create a value.
|
|
7
7
|
*/
|
|
8
|
-
create: () => Promise<
|
|
8
|
+
create: () => Promise<T> | T;
|
|
9
9
|
/**
|
|
10
10
|
* The function to destroy a value.
|
|
11
11
|
*/
|
|
12
|
-
destroy: (value:
|
|
12
|
+
destroy: (value: T) => Promise<void> | void;
|
|
13
13
|
/**
|
|
14
14
|
* The retention period in milliseconds.
|
|
15
15
|
*/
|
|
@@ -19,22 +19,43 @@ export declare interface RetainerOptions {
|
|
|
19
19
|
/**
|
|
20
20
|
* Retains a value for a specified time.
|
|
21
21
|
*/
|
|
22
|
-
export declare class Retainer implements RetainerOptions {
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
export declare class Retainer<T = unknown> implements RetainerOptions<T> {
|
|
23
|
+
/**
|
|
24
|
+
* The counter for the number of active references.
|
|
25
|
+
*/
|
|
26
|
+
counter: number;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The value currently retained.
|
|
30
|
+
*/
|
|
31
|
+
value: T | null;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The function to create a value.
|
|
35
|
+
*/
|
|
36
|
+
create: () => Promise<T> | T;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The function to destroy a value.
|
|
40
|
+
*/
|
|
41
|
+
destroy: (value: T) => Promise<void> | void;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The retention period in milliseconds.
|
|
45
|
+
*/
|
|
25
46
|
retentionPeriod: number;
|
|
26
47
|
|
|
27
48
|
/**
|
|
28
49
|
* Creates a new retainer.
|
|
29
50
|
* @param options The options for the retainer.
|
|
30
51
|
*/
|
|
31
|
-
constructor(options: RetainerOptions);
|
|
52
|
+
constructor(options: RetainerOptions<T>);
|
|
32
53
|
|
|
33
54
|
/**
|
|
34
55
|
* Retrieves the retained value.
|
|
35
56
|
* @returns The retained value as a promise.
|
|
36
57
|
*/
|
|
37
|
-
async get(): Promise<
|
|
58
|
+
async get(): Promise<T>;
|
|
38
59
|
|
|
39
60
|
/**
|
|
40
61
|
* Releases the retained value.
|
package/src/Scheduler.d.ts
CHANGED
|
@@ -5,24 +5,49 @@ import MicroTaskQueue from './MicroTaskQueue';
|
|
|
5
5
|
* A task that will be executed at a later time by `Scheduler`.
|
|
6
6
|
*/
|
|
7
7
|
export declare class Task extends MicroTask {
|
|
8
|
+
/**
|
|
9
|
+
* The function to execute.
|
|
10
|
+
*/
|
|
11
|
+
fn: (task: Task, scheduler: Scheduler) => void;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The time in milliseconds (Unix timestamp) when the task is scheduled to run.
|
|
15
|
+
*/
|
|
16
|
+
time: number;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The delay in milliseconds before the task is executed.
|
|
20
|
+
*/
|
|
21
|
+
delay: number;
|
|
22
|
+
|
|
8
23
|
/**
|
|
9
24
|
* Creates a new task.
|
|
10
25
|
* @param delay The delay before the task is executed. It can be a number of milliseconds or a `Date` object as an absolute time.
|
|
11
26
|
* @param fn The function to execute.
|
|
12
27
|
*/
|
|
13
|
-
constructor(delay: number | Date, fn: () => void);
|
|
28
|
+
constructor(delay: number | Date, fn: (task: Task, scheduler: Scheduler) => void);
|
|
14
29
|
}
|
|
15
30
|
|
|
16
31
|
/**
|
|
17
32
|
* A scheduler that manages tasks to be executed at a later time.
|
|
18
33
|
*/
|
|
19
34
|
export declare class Scheduler extends MicroTaskQueue {
|
|
35
|
+
/**
|
|
36
|
+
* Whether the scheduler is paused.
|
|
37
|
+
*/
|
|
38
|
+
paused: boolean;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The tolerance for comparing starting time of tasks.
|
|
42
|
+
*/
|
|
43
|
+
tolerance: number;
|
|
44
|
+
|
|
20
45
|
/**
|
|
21
46
|
* Creates a new scheduler.
|
|
22
47
|
* @param paused Whether the scheduler should start paused.
|
|
23
48
|
* @param tolerance The tolerance for comparing starting time of tasks.
|
|
24
49
|
*/
|
|
25
|
-
constructor(paused
|
|
50
|
+
constructor(paused?: boolean, tolerance: number = 4);
|
|
26
51
|
|
|
27
52
|
/**
|
|
28
53
|
* Whether the scheduler is empty.
|
package/src/Throttler.d.ts
CHANGED
|
@@ -5,11 +5,11 @@ export declare type ThrottlerOptions = {
|
|
|
5
5
|
/**
|
|
6
6
|
* The throttle timeout.
|
|
7
7
|
*/
|
|
8
|
-
throttleTimeout
|
|
8
|
+
throttleTimeout?: number;
|
|
9
9
|
/**
|
|
10
10
|
* The timeout for keys that have never been seen.
|
|
11
11
|
*/
|
|
12
|
-
neverSeenTimeout
|
|
12
|
+
neverSeenTimeout?: number;
|
|
13
13
|
/**
|
|
14
14
|
* The vacuum period.
|
|
15
15
|
*/
|
|
@@ -20,9 +20,25 @@ export declare type ThrottlerOptions = {
|
|
|
20
20
|
* A throttler that throttles the execution of tasks based on a key.
|
|
21
21
|
*/
|
|
22
22
|
export declare class Throttler implements ThrottlerOptions {
|
|
23
|
+
/**
|
|
24
|
+
* The throttle timeout.
|
|
25
|
+
*/
|
|
23
26
|
throttleTimeout: number;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The timeout for keys that have never been seen.
|
|
30
|
+
*/
|
|
24
31
|
neverSeenTimeout: number;
|
|
25
|
-
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The vacuum period.
|
|
35
|
+
*/
|
|
36
|
+
vacuumPeriod: number;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The last seen times for keys.
|
|
40
|
+
*/
|
|
41
|
+
lastSeen: Map<unknown, number>;
|
|
26
42
|
|
|
27
43
|
/**
|
|
28
44
|
* Creates a new throttler.
|
package/src/audit.d.ts
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* @param ms The minimum time interval between function calls, in milliseconds.
|
|
8
8
|
* @returns An audited version of the function.
|
|
9
9
|
*/
|
|
10
|
-
export declare function audit(
|
|
11
|
-
fn:
|
|
10
|
+
export declare function audit<T extends (...args: any[]) => void>(
|
|
11
|
+
fn: T,
|
|
12
12
|
ms: number
|
|
13
|
-
): (...args:
|
|
13
|
+
): (...args: Parameters<T>) => void;
|
|
14
14
|
|
|
15
15
|
export default audit;
|
package/src/debounce.d.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* @param ms The minimum time interval between function calls, in milliseconds.
|
|
7
7
|
* @returns A debounced version of the function.
|
|
8
8
|
*/
|
|
9
|
-
export declare function debounce(
|
|
10
|
-
fn:
|
|
9
|
+
export declare function debounce<T extends (...args: any[]) => void>(
|
|
10
|
+
fn: T,
|
|
11
11
|
ms: number
|
|
12
|
-
): (...args:
|
|
12
|
+
): (...args: Parameters<T>) => void;
|
|
13
13
|
|
|
14
14
|
export default debounce;
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare module 'time-queues' {
|
|
2
|
+
export * from './audit';
|
|
3
|
+
export * from './debounce';
|
|
4
|
+
export * from './defer';
|
|
5
|
+
export * from './sample';
|
|
6
|
+
export * from './sleep';
|
|
7
|
+
export * from './throttle';
|
|
8
|
+
|
|
9
|
+
export * from './MicroTask';
|
|
10
|
+
export * from './MicroTaskQueue';
|
|
11
|
+
export * from './ListQueue';
|
|
12
|
+
export * from './FrameQueue';
|
|
13
|
+
export * from './IdleQueue';
|
|
14
|
+
|
|
15
|
+
export * from './PageWatcher';
|
|
16
|
+
export * from './Scheduler';
|
|
17
|
+
export * from './Retainer';
|
|
18
|
+
export * from './Throttler';
|
|
19
|
+
|
|
20
|
+
export * from './when-dom-loaded';
|
|
21
|
+
export * from './when-loaded';
|
|
22
|
+
}
|
package/src/sample.d.ts
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
* @param ms The minimum time interval between function calls, in milliseconds.
|
|
10
10
|
* @returns A sampled version of the function.
|
|
11
11
|
*/
|
|
12
|
-
export declare function sample(
|
|
13
|
-
fn:
|
|
12
|
+
export declare function sample<T extends (...args: any[]) => void>(
|
|
13
|
+
fn: T,
|
|
14
14
|
ms: number
|
|
15
|
-
): (...args:
|
|
15
|
+
): (...args: Parameters<T>) => void;
|
|
16
16
|
|
|
17
17
|
export default sample;
|
package/src/throttle.d.ts
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* @param ms The minimum time interval between function calls, in milliseconds.
|
|
8
8
|
* @returns A throttled version of the function.
|
|
9
9
|
*/
|
|
10
|
-
export declare function throttle(
|
|
11
|
-
fn:
|
|
10
|
+
export declare function throttle<T extends (...args: any[]) => void>(
|
|
11
|
+
fn: T,
|
|
12
12
|
ms: number
|
|
13
|
-
): (...args:
|
|
13
|
+
): (...args: Parameters<T>) => void;
|
|
14
14
|
|
|
15
15
|
export default throttle;
|