@oscarpalmer/timer 0.43.0 → 0.45.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.
- package/dist/constants.d.mts +6 -19
- package/dist/constants.mjs +5 -13
- package/dist/global.d.mts +4 -2
- package/dist/global.mjs +5 -14
- package/dist/index.d.mts +52 -95
- package/dist/index.mjs +232 -411
- package/dist/is.d.mts +1 -3
- package/dist/misc.d.mts +10 -0
- package/dist/misc.mjs +34 -0
- package/dist/models.d.mts +110 -7
- package/dist/repeat.d.mts +3 -3
- package/dist/repeat.mjs +3 -3
- package/dist/timer.d.mts +3 -50
- package/dist/timer.mjs +50 -94
- package/dist/wait.d.mts +3 -2
- package/dist/wait.mjs +3 -3
- package/dist/when.d.mts +3 -46
- package/dist/when.mjs +77 -117
- package/dist/work.d.mts +3 -5
- package/dist/work.mjs +26 -31
- package/package.json +8 -8
- package/src/constants.ts +8 -19
- package/src/global.ts +12 -22
- package/src/index.ts +4 -5
- package/src/is.ts +1 -2
- package/src/misc.ts +49 -0
- package/src/models.ts +129 -6
- package/src/repeat.ts +4 -6
- package/src/timer.ts +60 -130
- package/src/wait.ts +4 -6
- package/src/when.ts +98 -153
- package/src/work.ts +33 -57
- package/dist/delay.d.mts +0 -3
- package/dist/delay.mjs +0 -2
- package/dist/get.d.mts +0 -8
- package/dist/get.mjs +0 -15
- package/src/delay.ts +0 -2
- package/src/get.ts +0 -17
package/dist/is.d.mts
CHANGED
package/dist/misc.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TimerState, TimerStates } from "./models.mjs";
|
|
2
|
+
import { GenericCallback } from "@oscarpalmer/atoms/models";
|
|
3
|
+
//#region src/misc.d.ts
|
|
4
|
+
declare function getCallback(value: unknown): GenericCallback;
|
|
5
|
+
declare function getValidNumber(value: unknown, defaultValue?: number): number;
|
|
6
|
+
declare function getValidTimeout(value: unknown): number;
|
|
7
|
+
declare function onVisibilityChange(): void;
|
|
8
|
+
declare function updateStates(state: TimerState, key?: keyof TimerStates): void;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { getCallback, getValidNumber, getValidTimeout, onVisibilityChange, updateStates };
|
package/dist/misc.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DEFAULT_TIMEOUT, STATES, WORK_CONTINUE, WORK_PAUSE } from "./constants.mjs";
|
|
2
|
+
import { work } from "./work.mjs";
|
|
3
|
+
import { noop } from "@oscarpalmer/atoms/function";
|
|
4
|
+
//#region src/misc.ts
|
|
5
|
+
function getCallback(value) {
|
|
6
|
+
return typeof value === "function" ? value : noop;
|
|
7
|
+
}
|
|
8
|
+
function getValidNumber(value, defaultValue) {
|
|
9
|
+
const actualDefault = defaultValue ?? 0;
|
|
10
|
+
return typeof value === "number" && value > actualDefault ? value : actualDefault;
|
|
11
|
+
}
|
|
12
|
+
function getValidTimeout(value) {
|
|
13
|
+
return typeof value === "number" && value > 0 ? value : DEFAULT_TIMEOUT;
|
|
14
|
+
}
|
|
15
|
+
/* istanbul ignore next */
|
|
16
|
+
function onVisibilityChange() {
|
|
17
|
+
const from = document.hidden ? STATES.active : STATES.hidden;
|
|
18
|
+
const type = document.hidden ? WORK_PAUSE : WORK_CONTINUE;
|
|
19
|
+
for (const stored of from) {
|
|
20
|
+
const state = stored instanceof WeakRef ? stored.deref() : stored;
|
|
21
|
+
if (state != null) work(type, state, true);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function updateStates(state, key) {
|
|
25
|
+
STATES.active.delete(state);
|
|
26
|
+
const hidden = [...STATES.hidden].find((stored) => stored.deref() === state);
|
|
27
|
+
/* istanbul ignore next */
|
|
28
|
+
if (hidden != null) STATES.hidden.delete(hidden);
|
|
29
|
+
if (key != null)
|
|
30
|
+
/* istanbul ignore next */
|
|
31
|
+
STATES[key].add(key === "hidden" ? new WeakRef(state) : state);
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { getCallback, getValidNumber, getValidTimeout, onVisibilityChange, updateStates };
|
package/dist/models.d.mts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Timer } from "./timer.mjs";
|
|
2
|
-
|
|
3
1
|
//#region src/models.d.ts
|
|
4
2
|
/**
|
|
5
3
|
* Options for a repeating timer
|
|
@@ -26,6 +24,53 @@ type RepeatOptions = {
|
|
|
26
24
|
*/
|
|
27
25
|
timeout: number;
|
|
28
26
|
};
|
|
27
|
+
type Timer = {
|
|
28
|
+
/**
|
|
29
|
+
* Is the timer active?
|
|
30
|
+
*/
|
|
31
|
+
get active(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Is the timer destroyed?
|
|
34
|
+
*
|
|
35
|
+
* @deprecated Timers take care of their own cleanup; this always returns `false`
|
|
36
|
+
*/
|
|
37
|
+
get destroyed(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Is the timer paused?
|
|
40
|
+
*/
|
|
41
|
+
get paused(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Get the timer's origin _(if debugging is enabled)_
|
|
44
|
+
*/
|
|
45
|
+
get trace(): string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Continue running the timer _(if it's paused)_
|
|
48
|
+
*/
|
|
49
|
+
continue(): Timer;
|
|
50
|
+
/**
|
|
51
|
+
* Destroy the timer
|
|
52
|
+
*
|
|
53
|
+
* @deprecated Timers take care of their own cleanup
|
|
54
|
+
*/
|
|
55
|
+
destroy(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Pause the timer _(if it's running)_
|
|
58
|
+
*/
|
|
59
|
+
pause(): Timer;
|
|
60
|
+
/**
|
|
61
|
+
* Restart the timer _(or start it, if it's not running)_
|
|
62
|
+
*/
|
|
63
|
+
restart(): Timer;
|
|
64
|
+
/**
|
|
65
|
+
* Start the timer _(if it's not running)_
|
|
66
|
+
*/
|
|
67
|
+
start(): Timer;
|
|
68
|
+
/**
|
|
69
|
+
* Stop the timer _(if it's running)_
|
|
70
|
+
*/
|
|
71
|
+
stop(): Timer;
|
|
72
|
+
};
|
|
73
|
+
type TimerName = 'repeat' | 'wait' | 'when';
|
|
29
74
|
type TimerOptions = {
|
|
30
75
|
onAfter: ((finished: boolean) => void) | undefined;
|
|
31
76
|
onError: (() => void) | undefined;
|
|
@@ -38,16 +83,73 @@ type TimerState = {
|
|
|
38
83
|
callback: () => void;
|
|
39
84
|
destroyed: boolean;
|
|
40
85
|
elapsed: number;
|
|
41
|
-
frame
|
|
86
|
+
frame?: number;
|
|
42
87
|
index: number;
|
|
88
|
+
name: TimerName;
|
|
89
|
+
options: TimerOptions;
|
|
43
90
|
paused: boolean;
|
|
91
|
+
timer: Timer;
|
|
44
92
|
total: number;
|
|
45
|
-
trace
|
|
93
|
+
trace?: string;
|
|
94
|
+
};
|
|
95
|
+
type TimerStates = {
|
|
96
|
+
/**
|
|
97
|
+
* A set of all active timers
|
|
98
|
+
*/
|
|
99
|
+
active: Set<TimerState>;
|
|
100
|
+
/**
|
|
101
|
+
* A set of timers that were paused due to the document being hidden
|
|
102
|
+
*/
|
|
103
|
+
hidden: Set<WeakRef<TimerState>>;
|
|
46
104
|
};
|
|
47
105
|
declare class TimerTrace extends Error {
|
|
48
106
|
constructor();
|
|
49
107
|
}
|
|
50
|
-
type
|
|
108
|
+
type When = {
|
|
109
|
+
/**
|
|
110
|
+
* Is the timer active?
|
|
111
|
+
*/
|
|
112
|
+
get active(): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Is the timer destroyed?
|
|
115
|
+
*
|
|
116
|
+
* @deprecated Timers take care of their own cleanup; this always returns `false`
|
|
117
|
+
*/
|
|
118
|
+
get destroyed(): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Is the timer paused?
|
|
121
|
+
*/
|
|
122
|
+
get paused(): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Get the timer's origin _(if debugging is enabled)_
|
|
125
|
+
*/
|
|
126
|
+
get trace(): string | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Continues the timer _(if it was paused)_
|
|
129
|
+
*/
|
|
130
|
+
continue(): When;
|
|
131
|
+
/**
|
|
132
|
+
* Destroys the timer _(and stops it,if it was running)_
|
|
133
|
+
*
|
|
134
|
+
* @deprecated Timers take care of their own cleanup
|
|
135
|
+
*/
|
|
136
|
+
destroy(): void;
|
|
137
|
+
/**
|
|
138
|
+
* Pauses the timer _(if it was running)_
|
|
139
|
+
*/
|
|
140
|
+
pause(): When;
|
|
141
|
+
/**
|
|
142
|
+
* Start the timer
|
|
143
|
+
*
|
|
144
|
+
* @param resolve Optional resolve callback
|
|
145
|
+
* @returns Promise that resolves when the condition is met
|
|
146
|
+
*/
|
|
147
|
+
start(resolve?: (() => void) | null): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Stops the timer _(if it was running)_
|
|
150
|
+
*/
|
|
151
|
+
stop(): When;
|
|
152
|
+
};
|
|
51
153
|
/**
|
|
52
154
|
* Options for a conditional timer
|
|
53
155
|
*/
|
|
@@ -69,14 +171,15 @@ type WhenState = {
|
|
|
69
171
|
promise: Promise<void>;
|
|
70
172
|
rejecter?: () => void;
|
|
71
173
|
resolver?: () => void;
|
|
174
|
+
result: boolean;
|
|
72
175
|
started: boolean;
|
|
73
176
|
timer: Timer;
|
|
74
177
|
};
|
|
75
178
|
type WorkHandler = (type: WorkHandlerType, timer: WorkHandlerTimer, state: TimerState, options: TimerOptions) => Timer;
|
|
76
179
|
type WorkHandlerTimer = {
|
|
77
180
|
instance: Timer;
|
|
78
|
-
|
|
181
|
+
name: TimerName;
|
|
79
182
|
};
|
|
80
183
|
type WorkHandlerType = 'continue' | 'pause' | 'restart' | 'start' | 'stop';
|
|
81
184
|
//#endregion
|
|
82
|
-
export { RepeatOptions, TimerOptions, TimerState, TimerTrace,
|
|
185
|
+
export { RepeatOptions, Timer, TimerName, TimerOptions, TimerState, TimerStates, TimerTrace, When, WhenOptions, WhenState, WorkHandler, WorkHandlerTimer, WorkHandlerType };
|
package/dist/repeat.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Timer } from "./
|
|
2
|
-
import
|
|
1
|
+
import { RepeatOptions, Timer } from "./models.mjs";
|
|
2
|
+
import "./global.mjs";
|
|
3
3
|
//#region src/repeat.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Create a repeating timer
|
|
@@ -10,4 +10,4 @@ import { RepeatOptions } from "./models.mjs";
|
|
|
10
10
|
*/
|
|
11
11
|
declare function repeat(callback: (index: number) => void, options?: Partial<RepeatOptions>): Timer;
|
|
12
12
|
//#endregion
|
|
13
|
-
export {
|
|
13
|
+
export { repeat };
|
package/dist/repeat.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TYPE_REPEAT } from "./constants.mjs";
|
|
2
|
-
import { getCallback, getValidNumber } from "./
|
|
2
|
+
import { getCallback, getValidNumber } from "./misc.mjs";
|
|
3
3
|
import "./global.mjs";
|
|
4
4
|
import { TimerTrace } from "./models.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { createTimer } from "./timer.mjs";
|
|
6
6
|
//#region src/repeat.ts
|
|
7
7
|
/**
|
|
8
8
|
* Create a repeating timer
|
|
@@ -12,7 +12,7 @@ import { Timer } from "./timer.mjs";
|
|
|
12
12
|
* @returns Timer instance
|
|
13
13
|
*/
|
|
14
14
|
function repeat(callback, options) {
|
|
15
|
-
return
|
|
15
|
+
return createTimer(TYPE_REPEAT, {
|
|
16
16
|
callback: getCallback(callback),
|
|
17
17
|
trace: new TimerTrace().stack
|
|
18
18
|
}, {
|
package/dist/timer.d.mts
CHANGED
|
@@ -1,52 +1,5 @@
|
|
|
1
|
-
import { TimerOptions, TimerState
|
|
2
|
-
|
|
1
|
+
import { Timer, TimerName, TimerOptions, TimerState } from "./models.mjs";
|
|
3
2
|
//#region src/timer.d.ts
|
|
4
|
-
declare
|
|
5
|
-
#private;
|
|
6
|
-
protected readonly options: TimerOptions;
|
|
7
|
-
private readonly $timer;
|
|
8
|
-
protected readonly state: TimerState;
|
|
9
|
-
/**
|
|
10
|
-
* Is the timer active?
|
|
11
|
-
*/
|
|
12
|
-
get active(): boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Is the timer destroyed?
|
|
15
|
-
*/
|
|
16
|
-
get destroyed(): boolean;
|
|
17
|
-
/**
|
|
18
|
-
* Is the timer paused?
|
|
19
|
-
*/
|
|
20
|
-
get paused(): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Get the timer's origin _(if debugging is enabled)_
|
|
23
|
-
*/
|
|
24
|
-
get trace(): string | undefined;
|
|
25
|
-
constructor(type: TimerType, state: Pick<TimerState, 'callback' | 'trace'>, options: TimerOptions, start: boolean);
|
|
26
|
-
/**
|
|
27
|
-
* Continue running the timer _(if it's paused)_
|
|
28
|
-
*/
|
|
29
|
-
continue(): Timer;
|
|
30
|
-
/**
|
|
31
|
-
* Destroy the timer
|
|
32
|
-
*/
|
|
33
|
-
destroy(): void;
|
|
34
|
-
/**
|
|
35
|
-
* Pause the timer _(if it's running)_
|
|
36
|
-
*/
|
|
37
|
-
pause(): Timer;
|
|
38
|
-
/**
|
|
39
|
-
* Restart the timer _(or start it, if it's not running)_
|
|
40
|
-
*/
|
|
41
|
-
restart(): Timer;
|
|
42
|
-
/**
|
|
43
|
-
* Start the timer _(if it's not running)_
|
|
44
|
-
*/
|
|
45
|
-
start(): Timer;
|
|
46
|
-
/**
|
|
47
|
-
* Stop the timer _(if it's running)_
|
|
48
|
-
*/
|
|
49
|
-
stop(): Timer;
|
|
50
|
-
}
|
|
3
|
+
declare function createTimer(name: TimerName, pick: Pick<TimerState, 'callback' | 'trace'>, options: TimerOptions, start: boolean): Timer;
|
|
51
4
|
//#endregion
|
|
52
|
-
export {
|
|
5
|
+
export { createTimer };
|
package/dist/timer.mjs
CHANGED
|
@@ -1,98 +1,54 @@
|
|
|
1
1
|
import { WORK_CONTINUE, WORK_PAUSE, WORK_RESTART, WORK_START, WORK_STOP } from "./constants.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { work } from "./work.mjs";
|
|
3
3
|
import { noop } from "@oscarpalmer/atoms/function";
|
|
4
4
|
//#region src/timer.ts
|
|
5
|
-
|
|
6
|
-
state
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* Destroy the timer
|
|
54
|
-
*/
|
|
55
|
-
destroy() {
|
|
56
|
-
this.state.destroyed = true;
|
|
57
|
-
this.options.onAfter = noop;
|
|
58
|
-
this.options.onError = noop;
|
|
59
|
-
this.state.callback = noop;
|
|
60
|
-
if (!globalThis._oscarpalmer_timer_debug) this.state.trace = void 0;
|
|
61
|
-
stop({
|
|
62
|
-
instance: this,
|
|
63
|
-
type: this.$timer
|
|
64
|
-
}, this.state, this.options);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Pause the timer _(if it's running)_
|
|
68
|
-
*/
|
|
69
|
-
pause() {
|
|
70
|
-
return this.#work(WORK_PAUSE);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Restart the timer _(or start it, if it's not running)_
|
|
74
|
-
*/
|
|
75
|
-
restart() {
|
|
76
|
-
return this.#work(WORK_RESTART);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Start the timer _(if it's not running)_
|
|
80
|
-
*/
|
|
81
|
-
start() {
|
|
82
|
-
return this.#work(WORK_START);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Stop the timer _(if it's running)_
|
|
86
|
-
*/
|
|
87
|
-
stop() {
|
|
88
|
-
return this.#work(WORK_STOP);
|
|
89
|
-
}
|
|
90
|
-
#work(type) {
|
|
91
|
-
return work(type, {
|
|
92
|
-
instance: this,
|
|
93
|
-
type: this.$timer
|
|
94
|
-
}, this.state, this.options);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
5
|
+
function createTimer(name, pick, options, start) {
|
|
6
|
+
const state = {
|
|
7
|
+
...pick,
|
|
8
|
+
name,
|
|
9
|
+
options,
|
|
10
|
+
active: false,
|
|
11
|
+
destroyed: false,
|
|
12
|
+
elapsed: 0,
|
|
13
|
+
frame: void 0,
|
|
14
|
+
index: 0,
|
|
15
|
+
paused: false,
|
|
16
|
+
timer: void 0,
|
|
17
|
+
total: 0
|
|
18
|
+
};
|
|
19
|
+
const instance = {
|
|
20
|
+
continue: () => work(WORK_CONTINUE, state),
|
|
21
|
+
destroy: noop,
|
|
22
|
+
pause: () => work(WORK_PAUSE, state),
|
|
23
|
+
restart: () => work(WORK_RESTART, state),
|
|
24
|
+
start: () => work(WORK_START, state),
|
|
25
|
+
stop: () => work(WORK_STOP, state)
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperties(instance, {
|
|
28
|
+
$timer: {
|
|
29
|
+
enumerable: false,
|
|
30
|
+
value: name
|
|
31
|
+
},
|
|
32
|
+
active: {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: () => state.active
|
|
35
|
+
},
|
|
36
|
+
destroyed: {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
value: false
|
|
39
|
+
},
|
|
40
|
+
paused: {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: () => state.paused
|
|
43
|
+
},
|
|
44
|
+
trace: {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: () => globalThis._oscarpalmer_timer_debug ?? false ? state.trace : void 0
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
state.timer = Object.freeze(instance);
|
|
50
|
+
if (start) state.timer.start();
|
|
51
|
+
return state.timer;
|
|
52
|
+
}
|
|
97
53
|
//#endregion
|
|
98
|
-
export {
|
|
54
|
+
export { createTimer };
|
package/dist/wait.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Timer } from "./
|
|
1
|
+
import { Timer } from "./models.mjs";
|
|
2
|
+
import "./global.mjs";
|
|
2
3
|
//#region src/wait.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Create a waiting timer
|
|
@@ -8,4 +9,4 @@ import { Timer } from "./timer.mjs";
|
|
|
8
9
|
*/
|
|
9
10
|
declare function wait(callback: () => void, time?: number): Timer;
|
|
10
11
|
//#endregion
|
|
11
|
-
export {
|
|
12
|
+
export { wait };
|
package/dist/wait.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TYPE_WAIT } from "./constants.mjs";
|
|
2
|
-
import { getCallback, getValidNumber } from "./
|
|
2
|
+
import { getCallback, getValidNumber } from "./misc.mjs";
|
|
3
3
|
import "./global.mjs";
|
|
4
4
|
import { TimerTrace } from "./models.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { createTimer } from "./timer.mjs";
|
|
6
6
|
//#region src/wait.ts
|
|
7
7
|
/**
|
|
8
8
|
* Create a waiting timer
|
|
@@ -11,7 +11,7 @@ import { Timer } from "./timer.mjs";
|
|
|
11
11
|
* @param time How long to wait for _(in milliseconds; defaults to screen refresh rate)_
|
|
12
12
|
*/
|
|
13
13
|
function wait(callback, time) {
|
|
14
|
-
return
|
|
14
|
+
return createTimer(TYPE_WAIT, {
|
|
15
15
|
callback: getCallback(callback),
|
|
16
16
|
trace: new TimerTrace().stack
|
|
17
17
|
}, {
|
package/dist/when.d.mts
CHANGED
|
@@ -1,49 +1,6 @@
|
|
|
1
|
-
import { WhenOptions } from "./models.mjs";
|
|
1
|
+
import { When, WhenOptions } from "./models.mjs";
|
|
2
|
+
import "./global.mjs";
|
|
2
3
|
//#region src/when.d.ts
|
|
3
|
-
declare class When {
|
|
4
|
-
private readonly $timer;
|
|
5
|
-
private readonly state;
|
|
6
|
-
/**
|
|
7
|
-
* Is the timer active?
|
|
8
|
-
*/
|
|
9
|
-
get active(): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Is the timer destroyed?
|
|
12
|
-
*/
|
|
13
|
-
get destroyed(): boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Is the timer paused?
|
|
16
|
-
*/
|
|
17
|
-
get paused(): boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Get the timer's origin _(if debugging is enabled)_
|
|
20
|
-
*/
|
|
21
|
-
get trace(): string | undefined;
|
|
22
|
-
constructor(condition: () => boolean, options?: Partial<WhenOptions>);
|
|
23
|
-
/**
|
|
24
|
-
* Continues the timer _(if it was paused)_
|
|
25
|
-
*/
|
|
26
|
-
continue(): When;
|
|
27
|
-
/**
|
|
28
|
-
* Destroys the timer _(and stops it,if it was running)_
|
|
29
|
-
*/
|
|
30
|
-
destroy(): void;
|
|
31
|
-
/**
|
|
32
|
-
* Pauses the timer _(if it was running)_
|
|
33
|
-
*/
|
|
34
|
-
pause(): When;
|
|
35
|
-
/**
|
|
36
|
-
* Start the timer
|
|
37
|
-
*
|
|
38
|
-
* @param resolve Optional resolve callback
|
|
39
|
-
* @returns Promise that resolves when the condition is met
|
|
40
|
-
*/
|
|
41
|
-
start(resolve?: (() => void) | null): Promise<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Stops the timer _(if it was running)_
|
|
44
|
-
*/
|
|
45
|
-
stop(): When;
|
|
46
|
-
}
|
|
47
4
|
/**
|
|
48
5
|
* Create a conditional timer
|
|
49
6
|
* @param condition Condition to check
|
|
@@ -52,4 +9,4 @@ declare class When {
|
|
|
52
9
|
*/
|
|
53
10
|
declare function when(condition: () => boolean, options?: Partial<WhenOptions>): When;
|
|
54
11
|
//#endregion
|
|
55
|
-
export {
|
|
12
|
+
export { when };
|