@oscarpalmer/timer 0.27.1 → 0.29.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.cjs +32 -4
- package/dist/constants.js +26 -9
- package/dist/delay.cjs +24 -0
- package/dist/delay.js +20 -0
- package/dist/get.cjs +15 -0
- package/dist/get.js +10 -0
- package/dist/global.cjs +17 -2
- package/dist/global.js +15 -1
- package/dist/index.cjs +16 -42
- package/dist/index.js +6 -48
- package/dist/is.cjs +11 -8
- package/dist/is.js +8 -12
- package/dist/models.cjs +5 -2
- package/dist/models.js +2 -3
- package/dist/node_modules/@oscarpalmer/atoms/dist/function.cjs +8 -0
- package/dist/node_modules/@oscarpalmer/atoms/dist/function.js +4 -0
- package/dist/repeat.cjs +30 -0
- package/dist/repeat.js +26 -0
- package/dist/timer.cjs +59 -71
- package/dist/timer.full.js +469 -0
- package/dist/timer.js +56 -72
- package/dist/wait.cjs +30 -0
- package/dist/wait.js +26 -0
- package/dist/when.cjs +59 -44
- package/dist/when.js +55 -44
- package/dist/work.cjs +72 -0
- package/dist/work.js +68 -0
- package/package.json +50 -9
- package/src/constants.ts +48 -6
- package/src/delay.ts +25 -0
- package/src/get.ts +12 -0
- package/src/global.ts +16 -1
- package/src/index.ts +5 -45
- package/src/is.ts +6 -6
- package/src/models.ts +55 -47
- package/src/repeat.ts +32 -0
- package/src/timer.ts +67 -151
- package/src/wait.ts +31 -0
- package/src/when.ts +49 -24
- package/src/work.ts +129 -0
- package/types/constants.d.cts +49 -74
- package/types/constants.d.ts +15 -6
- package/types/delay.d.cts +8 -0
- package/types/delay.d.ts +4 -0
- package/types/get.d.cts +7 -0
- package/types/get.d.ts +3 -0
- package/types/index.d.cts +89 -94
- package/types/index.d.ts +5 -6
- package/types/is.d.cts +50 -69
- package/types/models.d.cts +61 -63
- package/types/models.d.ts +43 -40
- package/types/repeat.d.cts +98 -0
- package/types/repeat.d.ts +7 -0
- package/types/timer.d.cts +35 -97
- package/types/timer.d.ts +19 -52
- package/types/wait.d.cts +83 -0
- package/types/wait.d.ts +8 -0
- package/types/when.d.cts +65 -69
- package/types/when.d.ts +18 -5
- package/types/work.d.cts +78 -0
- package/types/work.d.ts +3 -0
- package/dist/functions.cjs +0 -100
- package/dist/functions.js +0 -100
- package/dist/timer.iife.js +0 -429
- package/src/functions.ts +0 -158
- package/types/functions.d.cts +0 -114
- package/types/functions.d.ts +0 -5
package/types/index.d.cts
CHANGED
|
@@ -1,140 +1,106 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
declare
|
|
4
|
-
|
|
5
|
-
protected readonly
|
|
6
|
-
|
|
3
|
+
export declare class Timer {
|
|
4
|
+
#private;
|
|
5
|
+
protected readonly worker: WorkHandler;
|
|
6
|
+
protected readonly options: TimerOptions;
|
|
7
|
+
private readonly $timer;
|
|
8
|
+
protected readonly state: TimerState;
|
|
7
9
|
/**
|
|
8
|
-
* Is the timer
|
|
10
|
+
* Is the timer active?
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
get active(): boolean;
|
|
11
13
|
/**
|
|
12
14
|
* Is the timer destroyed?
|
|
13
15
|
*/
|
|
14
|
-
|
|
16
|
+
get destroyed(): boolean;
|
|
15
17
|
/**
|
|
16
18
|
* Is the timer paused?
|
|
17
19
|
*/
|
|
18
|
-
|
|
20
|
+
get paused(): boolean;
|
|
19
21
|
/**
|
|
20
|
-
*
|
|
22
|
+
* Get the timer's origin _(if debugging is enabled)_
|
|
21
23
|
*/
|
|
22
|
-
abstract readonly trace: string | undefined;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* A timer that can be started, stopped, and restarted as neeeded
|
|
26
|
-
*/
|
|
27
|
-
export declare class Timer extends BasicTimer<TimerState> {
|
|
28
|
-
private readonly options;
|
|
29
|
-
get active(): boolean;
|
|
30
|
-
get destroyed(): boolean;
|
|
31
|
-
get paused(): boolean;
|
|
32
24
|
get trace(): string | undefined;
|
|
33
|
-
constructor(type: "
|
|
25
|
+
constructor(type: TimerType, worker: WorkHandler, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
|
|
34
26
|
/**
|
|
35
|
-
*
|
|
27
|
+
* Continue running the timer _(if it's paused)_
|
|
36
28
|
*/
|
|
37
29
|
continue(): Timer;
|
|
38
30
|
/**
|
|
39
|
-
*
|
|
31
|
+
* Destroy the timer
|
|
40
32
|
*/
|
|
41
33
|
destroy(): void;
|
|
42
34
|
/**
|
|
43
|
-
*
|
|
35
|
+
* Pause the timer _(if it's running)_
|
|
44
36
|
*/
|
|
45
37
|
pause(): Timer;
|
|
46
38
|
/**
|
|
47
|
-
*
|
|
39
|
+
* Restart the timer _(or start it, if it's not running)_
|
|
48
40
|
*/
|
|
49
41
|
restart(): Timer;
|
|
50
42
|
/**
|
|
51
|
-
*
|
|
43
|
+
* Start the timer _(if it's not running)_
|
|
52
44
|
*/
|
|
53
45
|
start(): Timer;
|
|
54
46
|
/**
|
|
55
|
-
*
|
|
47
|
+
* Stop the timer _(if it's running)_
|
|
56
48
|
*/
|
|
57
49
|
stop(): Timer;
|
|
58
50
|
}
|
|
59
51
|
/**
|
|
60
|
-
*
|
|
61
|
-
* - calls a callback after a certain amount of time...
|
|
62
|
-
* - ... and repeats it a certain amount of times
|
|
63
|
-
* ---
|
|
64
|
-
* - `options.count` defaults to `Infinity`
|
|
65
|
-
* - `options.interval` defaults to `1000/60` _(1 frame)_
|
|
66
|
-
* - `options.timeout` defaults to `Infinity`
|
|
67
|
-
*/
|
|
68
|
-
export declare function repeat(callback: IndexedCallback, options?: Partial<RepeatOptions>): Timer;
|
|
69
|
-
/**
|
|
70
|
-
* Creates a timer which calls a callback after a certain amount of time
|
|
71
|
-
*/
|
|
72
|
-
export declare function wait(callback: () => void): Timer;
|
|
73
|
-
/**
|
|
74
|
-
* Creates a timer which calls a callback after a certain amount of time
|
|
52
|
+
* Options for a repeating timer
|
|
75
53
|
*/
|
|
76
|
-
export
|
|
77
|
-
/**
|
|
78
|
-
* Creates a timer which calls a callback after a certain amount of time
|
|
79
|
-
* - `options.interval` defaults to `1000/60` _(1 frame)_
|
|
80
|
-
* - `options.timeout` defaults to `30_000` _(30 seconds)_
|
|
81
|
-
*/
|
|
82
|
-
export declare function wait(callback: () => void, options: Partial<WaitOptions>): Timer;
|
|
83
|
-
/**
|
|
84
|
-
* Callback that runs after the timer has finished (or is stopped)
|
|
85
|
-
* - `finished` is `true` if the timer was allowed to finish, and `false` if it was stopped
|
|
86
|
-
*/
|
|
87
|
-
export type AfterCallback = (finished: boolean) => void;
|
|
88
|
-
export type AnyCallback = (() => void) | IndexedCallback;
|
|
89
|
-
/**
|
|
90
|
-
* Callback that runs for each iteration of the timer
|
|
91
|
-
*/
|
|
92
|
-
export type IndexedCallback = (index: number) => void;
|
|
93
|
-
export type BaseOptions = {
|
|
94
|
-
/**
|
|
95
|
-
* Interval between each callback
|
|
96
|
-
*/
|
|
97
|
-
interval: number;
|
|
54
|
+
export type RepeatOptions = {
|
|
98
55
|
/**
|
|
99
|
-
*
|
|
56
|
+
* Callback to be called when the timer has stopped, either manually or by completing its work
|
|
100
57
|
*/
|
|
101
|
-
|
|
102
|
-
};
|
|
103
|
-
export type OptionsWithCount = {
|
|
58
|
+
onAfter: ((finished: boolean) => void) | undefined;
|
|
104
59
|
/**
|
|
105
60
|
* How many times the timer should repeat
|
|
106
61
|
*/
|
|
107
62
|
count: number;
|
|
108
|
-
} & BaseOptions;
|
|
109
|
-
export type OptionsWithError = {
|
|
110
63
|
/**
|
|
111
|
-
*
|
|
64
|
+
* The interval between each repeat
|
|
112
65
|
*/
|
|
113
|
-
|
|
66
|
+
interval: number;
|
|
67
|
+
};
|
|
68
|
+
export type TimerOptions = {
|
|
69
|
+
onAfter: ((finished: boolean) => void) | undefined;
|
|
70
|
+
onError: (() => void) | undefined;
|
|
71
|
+
count: number;
|
|
72
|
+
interval: number;
|
|
73
|
+
timeout: number;
|
|
114
74
|
};
|
|
115
|
-
export type RepeatOptions = {
|
|
116
|
-
/**
|
|
117
|
-
* Callback to run after the timer has finished (or is stopped)
|
|
118
|
-
* - `finished` is `true` if the timer was allowed to finish, and `false` if it was stopped
|
|
119
|
-
*/
|
|
120
|
-
afterCallback?: AfterCallback;
|
|
121
|
-
} & OptionsWithCount & OptionsWithError;
|
|
122
|
-
export type TimerOptions = {} & RepeatOptions;
|
|
123
75
|
export type TimerState = {
|
|
124
76
|
active: boolean;
|
|
125
|
-
callback:
|
|
77
|
+
callback: () => void;
|
|
126
78
|
destroyed: boolean;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
index?: number;
|
|
131
|
-
isRepeated: boolean;
|
|
132
|
-
minimum: number;
|
|
79
|
+
elapsed: number;
|
|
80
|
+
frame: number | undefined;
|
|
81
|
+
index: number;
|
|
133
82
|
paused: boolean;
|
|
134
|
-
|
|
83
|
+
total: number;
|
|
84
|
+
trace: string | undefined;
|
|
85
|
+
};
|
|
86
|
+
export type TimerType = "repeat" | "wait" | "when";
|
|
87
|
+
/**
|
|
88
|
+
* Options for a conditional timer
|
|
89
|
+
*/
|
|
90
|
+
export type WhenOptions = {
|
|
91
|
+
/**
|
|
92
|
+
* How many times the timer should check the condition
|
|
93
|
+
*/
|
|
94
|
+
count: number;
|
|
95
|
+
/**
|
|
96
|
+
* Then interval between each condtional check
|
|
97
|
+
*/
|
|
98
|
+
interval: number;
|
|
99
|
+
/**
|
|
100
|
+
* The timeout for the timer
|
|
101
|
+
*/
|
|
102
|
+
timeout: number;
|
|
135
103
|
};
|
|
136
|
-
export type WaitOptions = {} & BaseOptions & OptionsWithError;
|
|
137
|
-
export type WhenOptions = {} & OptionsWithCount;
|
|
138
104
|
export type WhenState = {
|
|
139
105
|
promise: Promise<void>;
|
|
140
106
|
rejecter?: () => void;
|
|
@@ -142,10 +108,30 @@ export type WhenState = {
|
|
|
142
108
|
started: boolean;
|
|
143
109
|
timer: Timer;
|
|
144
110
|
};
|
|
145
|
-
export
|
|
111
|
+
export type WorkHandler = (type: WorkHandlerType, timer: WorkHandlerTimer, state: TimerState, options: TimerOptions) => Timer;
|
|
112
|
+
export type WorkHandlerTimer = {
|
|
113
|
+
instance: Timer;
|
|
114
|
+
type: TimerType;
|
|
115
|
+
};
|
|
116
|
+
export type WorkHandlerType = "continue" | "pause" | "restart" | "start" | "stop";
|
|
117
|
+
export declare class When {
|
|
118
|
+
private readonly $timer;
|
|
119
|
+
private readonly state;
|
|
120
|
+
/**
|
|
121
|
+
* Is the timer active?
|
|
122
|
+
*/
|
|
146
123
|
get active(): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Is the timer destroyed?
|
|
126
|
+
*/
|
|
147
127
|
get destroyed(): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Is the timer paused?
|
|
130
|
+
*/
|
|
148
131
|
get paused(): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Get the timer's origin _(if debugging is enabled)_
|
|
134
|
+
*/
|
|
149
135
|
get trace(): string | undefined;
|
|
150
136
|
constructor(state: WhenState);
|
|
151
137
|
/**
|
|
@@ -170,10 +156,19 @@ export declare class When extends BasicTimer<WhenState> {
|
|
|
170
156
|
then(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void>;
|
|
171
157
|
}
|
|
172
158
|
/**
|
|
173
|
-
*
|
|
174
|
-
* - If the condition is never met in a timely manner, the promise will reject
|
|
159
|
+
* Create a conditional timer
|
|
175
160
|
*/
|
|
176
161
|
export declare function when(condition: () => boolean, options?: Partial<WhenOptions>): When;
|
|
162
|
+
/**
|
|
163
|
+
* Create a waiting timer
|
|
164
|
+
* @param callback Callback to run when the timer has finished
|
|
165
|
+
* @param time How long to wait for _(in milliseconds; defaults to screen refresh rate)_
|
|
166
|
+
*/
|
|
167
|
+
export declare function wait(callback: () => void, time?: number): Timer;
|
|
168
|
+
/**
|
|
169
|
+
* Create a repeating timer
|
|
170
|
+
*/
|
|
171
|
+
export declare function repeat(callback: (index: number) => void, options?: Partial<RepeatOptions>): Timer;
|
|
177
172
|
/**
|
|
178
173
|
* Is the value a repeating timer?
|
|
179
174
|
*/
|
|
@@ -191,8 +186,8 @@ export declare function isWaited(value: unknown): value is Timer;
|
|
|
191
186
|
*/
|
|
192
187
|
export declare function isWhen(value: unknown): value is When;
|
|
193
188
|
/**
|
|
194
|
-
*
|
|
189
|
+
* Create a delayed promise that resolves after a certain amount of time _(in milliseconds; defaults to screen refresh rate)_
|
|
195
190
|
*/
|
|
196
|
-
export declare function delay(time
|
|
191
|
+
export declare function delay(time?: number): Promise<void>;
|
|
197
192
|
|
|
198
193
|
export {};
|
package/types/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import './global';
|
|
2
|
-
|
|
3
|
-
* Creates a delayed promise that resolves after a certain amount of time _(or rejects when timed out)_
|
|
4
|
-
*/
|
|
5
|
-
export declare function delay(time: number, timeout?: number): Promise<void>;
|
|
2
|
+
export * from './delay';
|
|
6
3
|
export { isRepeated, isTimer, isWaited, isWhen } from './is';
|
|
7
|
-
export
|
|
8
|
-
export {
|
|
4
|
+
export * from './repeat';
|
|
5
|
+
export type { Timer } from './timer';
|
|
6
|
+
export * from './wait';
|
|
7
|
+
export * from './when';
|
package/types/is.d.cts
CHANGED
|
@@ -1,111 +1,72 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
declare
|
|
4
|
-
|
|
5
|
-
protected readonly
|
|
6
|
-
|
|
3
|
+
declare class Timer {
|
|
4
|
+
#private;
|
|
5
|
+
protected readonly worker: WorkHandler;
|
|
6
|
+
protected readonly options: TimerOptions;
|
|
7
|
+
private readonly $timer;
|
|
8
|
+
protected readonly state: TimerState;
|
|
7
9
|
/**
|
|
8
|
-
* Is the timer
|
|
10
|
+
* Is the timer active?
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
get active(): boolean;
|
|
11
13
|
/**
|
|
12
14
|
* Is the timer destroyed?
|
|
13
15
|
*/
|
|
14
|
-
|
|
16
|
+
get destroyed(): boolean;
|
|
15
17
|
/**
|
|
16
18
|
* Is the timer paused?
|
|
17
19
|
*/
|
|
18
|
-
|
|
20
|
+
get paused(): boolean;
|
|
19
21
|
/**
|
|
20
|
-
*
|
|
22
|
+
* Get the timer's origin _(if debugging is enabled)_
|
|
21
23
|
*/
|
|
22
|
-
abstract readonly trace: string | undefined;
|
|
23
|
-
}
|
|
24
|
-
declare class Timer extends BasicTimer<TimerState> {
|
|
25
|
-
private readonly options;
|
|
26
|
-
get active(): boolean;
|
|
27
|
-
get destroyed(): boolean;
|
|
28
|
-
get paused(): boolean;
|
|
29
24
|
get trace(): string | undefined;
|
|
30
|
-
constructor(type: "
|
|
25
|
+
constructor(type: TimerType, worker: WorkHandler, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
|
|
31
26
|
/**
|
|
32
|
-
*
|
|
27
|
+
* Continue running the timer _(if it's paused)_
|
|
33
28
|
*/
|
|
34
29
|
continue(): Timer;
|
|
35
30
|
/**
|
|
36
|
-
*
|
|
31
|
+
* Destroy the timer
|
|
37
32
|
*/
|
|
38
33
|
destroy(): void;
|
|
39
34
|
/**
|
|
40
|
-
*
|
|
35
|
+
* Pause the timer _(if it's running)_
|
|
41
36
|
*/
|
|
42
37
|
pause(): Timer;
|
|
43
38
|
/**
|
|
44
|
-
*
|
|
39
|
+
* Restart the timer _(or start it, if it's not running)_
|
|
45
40
|
*/
|
|
46
41
|
restart(): Timer;
|
|
47
42
|
/**
|
|
48
|
-
*
|
|
43
|
+
* Start the timer _(if it's not running)_
|
|
49
44
|
*/
|
|
50
45
|
start(): Timer;
|
|
51
46
|
/**
|
|
52
|
-
*
|
|
47
|
+
* Stop the timer _(if it's running)_
|
|
53
48
|
*/
|
|
54
49
|
stop(): Timer;
|
|
55
50
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
export type AfterCallback = (finished: boolean) => void;
|
|
61
|
-
export type AnyCallback = (() => void) | IndexedCallback;
|
|
62
|
-
/**
|
|
63
|
-
* Callback that runs for each iteration of the timer
|
|
64
|
-
*/
|
|
65
|
-
export type IndexedCallback = (index: number) => void;
|
|
66
|
-
export type BaseOptions = {
|
|
67
|
-
/**
|
|
68
|
-
* Interval between each callback
|
|
69
|
-
*/
|
|
51
|
+
export type TimerOptions = {
|
|
52
|
+
onAfter: ((finished: boolean) => void) | undefined;
|
|
53
|
+
onError: (() => void) | undefined;
|
|
54
|
+
count: number;
|
|
70
55
|
interval: number;
|
|
71
|
-
/**
|
|
72
|
-
* Maximum amount of time the timer may run for
|
|
73
|
-
*/
|
|
74
56
|
timeout: number;
|
|
75
57
|
};
|
|
76
|
-
export type OptionsWithCount = {
|
|
77
|
-
/**
|
|
78
|
-
* How many times the timer should repeat
|
|
79
|
-
*/
|
|
80
|
-
count: number;
|
|
81
|
-
} & BaseOptions;
|
|
82
|
-
export type OptionsWithError = {
|
|
83
|
-
/**
|
|
84
|
-
* Callback to run when an error occurs _(usually a timeout)_
|
|
85
|
-
*/
|
|
86
|
-
errorCallback?: () => void;
|
|
87
|
-
};
|
|
88
|
-
export type RepeatOptions = {
|
|
89
|
-
/**
|
|
90
|
-
* Callback to run after the timer has finished (or is stopped)
|
|
91
|
-
* - `finished` is `true` if the timer was allowed to finish, and `false` if it was stopped
|
|
92
|
-
*/
|
|
93
|
-
afterCallback?: AfterCallback;
|
|
94
|
-
} & OptionsWithCount & OptionsWithError;
|
|
95
|
-
export type TimerOptions = {} & RepeatOptions;
|
|
96
58
|
export type TimerState = {
|
|
97
59
|
active: boolean;
|
|
98
|
-
callback:
|
|
60
|
+
callback: () => void;
|
|
99
61
|
destroyed: boolean;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
index?: number;
|
|
104
|
-
isRepeated: boolean;
|
|
105
|
-
minimum: number;
|
|
62
|
+
elapsed: number;
|
|
63
|
+
frame: number | undefined;
|
|
64
|
+
index: number;
|
|
106
65
|
paused: boolean;
|
|
107
|
-
|
|
66
|
+
total: number;
|
|
67
|
+
trace: string | undefined;
|
|
108
68
|
};
|
|
69
|
+
export type TimerType = "repeat" | "wait" | "when";
|
|
109
70
|
export type WhenState = {
|
|
110
71
|
promise: Promise<void>;
|
|
111
72
|
rejecter?: () => void;
|
|
@@ -113,10 +74,30 @@ export type WhenState = {
|
|
|
113
74
|
started: boolean;
|
|
114
75
|
timer: Timer;
|
|
115
76
|
};
|
|
116
|
-
|
|
77
|
+
export type WorkHandler = (type: WorkHandlerType, timer: WorkHandlerTimer, state: TimerState, options: TimerOptions) => Timer;
|
|
78
|
+
export type WorkHandlerTimer = {
|
|
79
|
+
instance: Timer;
|
|
80
|
+
type: TimerType;
|
|
81
|
+
};
|
|
82
|
+
export type WorkHandlerType = "continue" | "pause" | "restart" | "start" | "stop";
|
|
83
|
+
declare class When {
|
|
84
|
+
private readonly $timer;
|
|
85
|
+
private readonly state;
|
|
86
|
+
/**
|
|
87
|
+
* Is the timer active?
|
|
88
|
+
*/
|
|
117
89
|
get active(): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Is the timer destroyed?
|
|
92
|
+
*/
|
|
118
93
|
get destroyed(): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Is the timer paused?
|
|
96
|
+
*/
|
|
119
97
|
get paused(): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Get the timer's origin _(if debugging is enabled)_
|
|
100
|
+
*/
|
|
120
101
|
get trace(): string | undefined;
|
|
121
102
|
constructor(state: WhenState);
|
|
122
103
|
/**
|
package/types/models.d.cts
CHANGED
|
@@ -1,116 +1,109 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
declare
|
|
4
|
-
|
|
5
|
-
protected readonly
|
|
6
|
-
|
|
3
|
+
declare class Timer {
|
|
4
|
+
#private;
|
|
5
|
+
protected readonly worker: WorkHandler;
|
|
6
|
+
protected readonly options: TimerOptions;
|
|
7
|
+
private readonly $timer;
|
|
8
|
+
protected readonly state: TimerState;
|
|
7
9
|
/**
|
|
8
|
-
* Is the timer
|
|
10
|
+
* Is the timer active?
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
get active(): boolean;
|
|
11
13
|
/**
|
|
12
14
|
* Is the timer destroyed?
|
|
13
15
|
*/
|
|
14
|
-
|
|
16
|
+
get destroyed(): boolean;
|
|
15
17
|
/**
|
|
16
18
|
* Is the timer paused?
|
|
17
19
|
*/
|
|
18
|
-
|
|
20
|
+
get paused(): boolean;
|
|
19
21
|
/**
|
|
20
|
-
*
|
|
22
|
+
* Get the timer's origin _(if debugging is enabled)_
|
|
21
23
|
*/
|
|
22
|
-
abstract readonly trace: string | undefined;
|
|
23
|
-
}
|
|
24
|
-
declare class Timer extends BasicTimer<TimerState> {
|
|
25
|
-
private readonly options;
|
|
26
|
-
get active(): boolean;
|
|
27
|
-
get destroyed(): boolean;
|
|
28
|
-
get paused(): boolean;
|
|
29
24
|
get trace(): string | undefined;
|
|
30
|
-
constructor(type: "
|
|
25
|
+
constructor(type: TimerType, worker: WorkHandler, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
|
|
31
26
|
/**
|
|
32
|
-
*
|
|
27
|
+
* Continue running the timer _(if it's paused)_
|
|
33
28
|
*/
|
|
34
29
|
continue(): Timer;
|
|
35
30
|
/**
|
|
36
|
-
*
|
|
31
|
+
* Destroy the timer
|
|
37
32
|
*/
|
|
38
33
|
destroy(): void;
|
|
39
34
|
/**
|
|
40
|
-
*
|
|
35
|
+
* Pause the timer _(if it's running)_
|
|
41
36
|
*/
|
|
42
37
|
pause(): Timer;
|
|
43
38
|
/**
|
|
44
|
-
*
|
|
39
|
+
* Restart the timer _(or start it, if it's not running)_
|
|
45
40
|
*/
|
|
46
41
|
restart(): Timer;
|
|
47
42
|
/**
|
|
48
|
-
*
|
|
43
|
+
* Start the timer _(if it's not running)_
|
|
49
44
|
*/
|
|
50
45
|
start(): Timer;
|
|
51
46
|
/**
|
|
52
|
-
*
|
|
47
|
+
* Stop the timer _(if it's running)_
|
|
53
48
|
*/
|
|
54
49
|
stop(): Timer;
|
|
55
50
|
}
|
|
56
51
|
/**
|
|
57
|
-
*
|
|
58
|
-
* - `finished` is `true` if the timer was allowed to finish, and `false` if it was stopped
|
|
59
|
-
*/
|
|
60
|
-
export type AfterCallback = (finished: boolean) => void;
|
|
61
|
-
export type AnyCallback = (() => void) | IndexedCallback;
|
|
62
|
-
/**
|
|
63
|
-
* Callback that runs for each iteration of the timer
|
|
52
|
+
* Options for a repeating timer
|
|
64
53
|
*/
|
|
65
|
-
export type
|
|
66
|
-
export type BaseOptions = {
|
|
54
|
+
export type RepeatOptions = {
|
|
67
55
|
/**
|
|
68
|
-
*
|
|
56
|
+
* Callback to be called when the timer has stopped, either manually or by completing its work
|
|
69
57
|
*/
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Maximum amount of time the timer may run for
|
|
73
|
-
*/
|
|
74
|
-
timeout: number;
|
|
75
|
-
};
|
|
76
|
-
export type OptionsWithCount = {
|
|
58
|
+
onAfter: ((finished: boolean) => void) | undefined;
|
|
77
59
|
/**
|
|
78
60
|
* How many times the timer should repeat
|
|
79
61
|
*/
|
|
80
62
|
count: number;
|
|
81
|
-
} & BaseOptions;
|
|
82
|
-
export type OptionsWithError = {
|
|
83
63
|
/**
|
|
84
|
-
*
|
|
64
|
+
* The interval between each repeat
|
|
85
65
|
*/
|
|
86
|
-
|
|
66
|
+
interval: number;
|
|
67
|
+
};
|
|
68
|
+
export type TimerOptions = {
|
|
69
|
+
onAfter: ((finished: boolean) => void) | undefined;
|
|
70
|
+
onError: (() => void) | undefined;
|
|
71
|
+
count: number;
|
|
72
|
+
interval: number;
|
|
73
|
+
timeout: number;
|
|
87
74
|
};
|
|
88
|
-
export type RepeatOptions = {
|
|
89
|
-
/**
|
|
90
|
-
* Callback to run after the timer has finished (or is stopped)
|
|
91
|
-
* - `finished` is `true` if the timer was allowed to finish, and `false` if it was stopped
|
|
92
|
-
*/
|
|
93
|
-
afterCallback?: AfterCallback;
|
|
94
|
-
} & OptionsWithCount & OptionsWithError;
|
|
95
|
-
export type TimerOptions = {} & RepeatOptions;
|
|
96
75
|
export type TimerState = {
|
|
97
76
|
active: boolean;
|
|
98
|
-
callback:
|
|
77
|
+
callback: () => void;
|
|
99
78
|
destroyed: boolean;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
index?: number;
|
|
104
|
-
isRepeated: boolean;
|
|
105
|
-
minimum: number;
|
|
79
|
+
elapsed: number;
|
|
80
|
+
frame: number | undefined;
|
|
81
|
+
index: number;
|
|
106
82
|
paused: boolean;
|
|
107
|
-
|
|
83
|
+
total: number;
|
|
84
|
+
trace: string | undefined;
|
|
108
85
|
};
|
|
109
86
|
export declare class TimerTrace extends Error {
|
|
110
87
|
constructor();
|
|
111
88
|
}
|
|
112
|
-
export type
|
|
113
|
-
|
|
89
|
+
export type TimerType = "repeat" | "wait" | "when";
|
|
90
|
+
/**
|
|
91
|
+
* Options for a conditional timer
|
|
92
|
+
*/
|
|
93
|
+
export type WhenOptions = {
|
|
94
|
+
/**
|
|
95
|
+
* How many times the timer should check the condition
|
|
96
|
+
*/
|
|
97
|
+
count: number;
|
|
98
|
+
/**
|
|
99
|
+
* Then interval between each condtional check
|
|
100
|
+
*/
|
|
101
|
+
interval: number;
|
|
102
|
+
/**
|
|
103
|
+
* The timeout for the timer
|
|
104
|
+
*/
|
|
105
|
+
timeout: number;
|
|
106
|
+
};
|
|
114
107
|
export type WhenState = {
|
|
115
108
|
promise: Promise<void>;
|
|
116
109
|
rejecter?: () => void;
|
|
@@ -118,6 +111,11 @@ export type WhenState = {
|
|
|
118
111
|
started: boolean;
|
|
119
112
|
timer: Timer;
|
|
120
113
|
};
|
|
121
|
-
export type
|
|
114
|
+
export type WorkHandler = (type: WorkHandlerType, timer: WorkHandlerTimer, state: TimerState, options: TimerOptions) => Timer;
|
|
115
|
+
export type WorkHandlerTimer = {
|
|
116
|
+
instance: Timer;
|
|
117
|
+
type: TimerType;
|
|
118
|
+
};
|
|
119
|
+
export type WorkHandlerType = "continue" | "pause" | "restart" | "start" | "stop";
|
|
122
120
|
|
|
123
121
|
export {};
|