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