@oscarpalmer/timer 0.28.0 → 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.
Files changed (67) hide show
  1. package/dist/constants.cjs +32 -4
  2. package/dist/constants.js +26 -9
  3. package/dist/delay.cjs +24 -0
  4. package/dist/delay.js +20 -0
  5. package/dist/get.cjs +15 -0
  6. package/dist/get.js +10 -0
  7. package/dist/global.cjs +17 -2
  8. package/dist/global.js +15 -1
  9. package/dist/index.cjs +16 -44
  10. package/dist/index.js +6 -50
  11. package/dist/is.cjs +11 -8
  12. package/dist/is.js +8 -12
  13. package/dist/models.cjs +5 -2
  14. package/dist/models.js +2 -3
  15. package/dist/node_modules/@oscarpalmer/atoms/dist/function.cjs +8 -0
  16. package/dist/node_modules/@oscarpalmer/atoms/dist/function.js +4 -0
  17. package/dist/repeat.cjs +30 -0
  18. package/dist/repeat.js +26 -0
  19. package/dist/timer.cjs +59 -71
  20. package/dist/timer.full.js +469 -0
  21. package/dist/timer.js +56 -72
  22. package/dist/wait.cjs +30 -0
  23. package/dist/wait.js +26 -0
  24. package/dist/when.cjs +59 -44
  25. package/dist/when.js +55 -44
  26. package/dist/work.cjs +72 -0
  27. package/dist/work.js +68 -0
  28. package/package.json +50 -9
  29. package/src/constants.ts +48 -6
  30. package/src/delay.ts +25 -0
  31. package/src/get.ts +12 -0
  32. package/src/global.ts +16 -1
  33. package/src/index.ts +5 -48
  34. package/src/is.ts +6 -6
  35. package/src/models.ts +55 -47
  36. package/src/repeat.ts +32 -0
  37. package/src/timer.ts +67 -151
  38. package/src/wait.ts +31 -0
  39. package/src/when.ts +49 -24
  40. package/src/work.ts +129 -0
  41. package/types/constants.d.cts +49 -74
  42. package/types/constants.d.ts +15 -6
  43. package/types/delay.d.cts +8 -0
  44. package/types/delay.d.ts +4 -0
  45. package/types/get.d.cts +7 -0
  46. package/types/get.d.ts +3 -0
  47. package/types/index.d.cts +89 -94
  48. package/types/index.d.ts +5 -6
  49. package/types/is.d.cts +50 -69
  50. package/types/models.d.cts +61 -63
  51. package/types/models.d.ts +43 -40
  52. package/types/repeat.d.cts +98 -0
  53. package/types/repeat.d.ts +7 -0
  54. package/types/timer.d.cts +35 -97
  55. package/types/timer.d.ts +19 -52
  56. package/types/wait.d.cts +83 -0
  57. package/types/wait.d.ts +8 -0
  58. package/types/when.d.cts +65 -69
  59. package/types/when.d.ts +18 -5
  60. package/types/work.d.cts +78 -0
  61. package/types/work.d.ts +3 -0
  62. package/dist/functions.cjs +0 -99
  63. package/dist/functions.js +0 -99
  64. package/dist/timer.iife.js +0 -431
  65. package/src/functions.ts +0 -158
  66. package/types/functions.d.cts +0 -113
  67. package/types/functions.d.ts +0 -4
package/types/index.d.cts CHANGED
@@ -1,140 +1,106 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- declare abstract class BasicTimer<State> {
4
- protected readonly $timer: string;
5
- protected readonly state: State;
6
- constructor(type: "repeat" | "wait" | "when", state: State);
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 running?
10
+ * Is the timer active?
9
11
  */
10
- abstract readonly active: boolean;
12
+ get active(): boolean;
11
13
  /**
12
14
  * Is the timer destroyed?
13
15
  */
14
- abstract readonly destroyed: boolean;
16
+ get destroyed(): boolean;
15
17
  /**
16
18
  * Is the timer paused?
17
19
  */
18
- abstract readonly paused: boolean;
20
+ get paused(): boolean;
19
21
  /**
20
- * Gets the traced location of the timer
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: "repeat" | "wait", state: TimerState, options: TimerOptions);
25
+ constructor(type: TimerType, worker: WorkHandler, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
34
26
  /**
35
- * Continues the timer _(if it was paused)_
27
+ * Continue running the timer _(if it's paused)_
36
28
  */
37
29
  continue(): Timer;
38
30
  /**
39
- * Destroys the timer _(after stopping it, if it was running)_
31
+ * Destroy the timer
40
32
  */
41
33
  destroy(): void;
42
34
  /**
43
- * Pauses the timer _(if it was running)_
35
+ * Pause the timer _(if it's running)_
44
36
  */
45
37
  pause(): Timer;
46
38
  /**
47
- * Restarts the timer _(if it was running)_
39
+ * Restart the timer _(or start it, if it's not running)_
48
40
  */
49
41
  restart(): Timer;
50
42
  /**
51
- * Starts the timer _(if it was stopped)_
43
+ * Start the timer _(if it's not running)_
52
44
  */
53
45
  start(): Timer;
54
46
  /**
55
- * Stops the timer _(if it was running)_
47
+ * Stop the timer _(if it's running)_
56
48
  */
57
49
  stop(): Timer;
58
50
  }
59
51
  /**
60
- * Creates a timer which:
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 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;
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
- * Maximum amount of time the timer may run for
56
+ * Callback to be called when the timer has stopped, either manually or by completing its work
100
57
  */
101
- timeout: number;
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
- * Callback to run when an error occurs _(usually a timeout)_
64
+ * The interval between each repeat
112
65
  */
113
- errorCallback?: () => void;
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: AnyCallback;
77
+ callback: () => void;
126
78
  destroyed: boolean;
127
- count?: number;
128
- elapsed?: number;
129
- frame?: number;
130
- index?: number;
131
- isRepeated: boolean;
132
- minimum: number;
79
+ elapsed: number;
80
+ frame: number | undefined;
81
+ index: number;
133
82
  paused: boolean;
134
- trace?: string;
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 declare class When extends BasicTimer<WhenState> {
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
- * - Creates a promise that resolves when a condition is met
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
- * Creates a delayed promise that resolves after a certain amount of time _(or rejects when timed out)_
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: number, timeout?: number): Promise<void>;
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 { repeat, wait, type Timer } from './timer';
8
- export { when, type When } from './when';
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 abstract class BasicTimer<State> {
4
- protected readonly $timer: string;
5
- protected readonly state: State;
6
- constructor(type: "repeat" | "wait" | "when", state: State);
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 running?
10
+ * Is the timer active?
9
11
  */
10
- abstract readonly active: boolean;
12
+ get active(): boolean;
11
13
  /**
12
14
  * Is the timer destroyed?
13
15
  */
14
- abstract readonly destroyed: boolean;
16
+ get destroyed(): boolean;
15
17
  /**
16
18
  * Is the timer paused?
17
19
  */
18
- abstract readonly paused: boolean;
20
+ get paused(): boolean;
19
21
  /**
20
- * Gets the traced location of the timer
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: "repeat" | "wait", state: TimerState, options: TimerOptions);
25
+ constructor(type: TimerType, worker: WorkHandler, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
31
26
  /**
32
- * Continues the timer _(if it was paused)_
27
+ * Continue running the timer _(if it's paused)_
33
28
  */
34
29
  continue(): Timer;
35
30
  /**
36
- * Destroys the timer _(after stopping it, if it was running)_
31
+ * Destroy the timer
37
32
  */
38
33
  destroy(): void;
39
34
  /**
40
- * Pauses the timer _(if it was running)_
35
+ * Pause the timer _(if it's running)_
41
36
  */
42
37
  pause(): Timer;
43
38
  /**
44
- * Restarts the timer _(if it was running)_
39
+ * Restart the timer _(or start it, if it's not running)_
45
40
  */
46
41
  restart(): Timer;
47
42
  /**
48
- * Starts the timer _(if it was stopped)_
43
+ * Start the timer _(if it's not running)_
49
44
  */
50
45
  start(): Timer;
51
46
  /**
52
- * Stops the timer _(if it was running)_
47
+ * Stop the timer _(if it's running)_
53
48
  */
54
49
  stop(): Timer;
55
50
  }
56
- /**
57
- * Callback that runs after the timer has finished (or is stopped)
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
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: AnyCallback;
60
+ callback: () => void;
99
61
  destroyed: boolean;
100
- count?: number;
101
- elapsed?: number;
102
- frame?: number;
103
- index?: number;
104
- isRepeated: boolean;
105
- minimum: number;
62
+ elapsed: number;
63
+ frame: number | undefined;
64
+ index: number;
106
65
  paused: boolean;
107
- trace?: string;
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
- declare class When extends BasicTimer<WhenState> {
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
  /**
@@ -1,116 +1,109 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- declare abstract class BasicTimer<State> {
4
- protected readonly $timer: string;
5
- protected readonly state: State;
6
- constructor(type: "repeat" | "wait" | "when", state: State);
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 running?
10
+ * Is the timer active?
9
11
  */
10
- abstract readonly active: boolean;
12
+ get active(): boolean;
11
13
  /**
12
14
  * Is the timer destroyed?
13
15
  */
14
- abstract readonly destroyed: boolean;
16
+ get destroyed(): boolean;
15
17
  /**
16
18
  * Is the timer paused?
17
19
  */
18
- abstract readonly paused: boolean;
20
+ get paused(): boolean;
19
21
  /**
20
- * Gets the traced location of the timer
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: "repeat" | "wait", state: TimerState, options: TimerOptions);
25
+ constructor(type: TimerType, worker: WorkHandler, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
31
26
  /**
32
- * Continues the timer _(if it was paused)_
27
+ * Continue running the timer _(if it's paused)_
33
28
  */
34
29
  continue(): Timer;
35
30
  /**
36
- * Destroys the timer _(after stopping it, if it was running)_
31
+ * Destroy the timer
37
32
  */
38
33
  destroy(): void;
39
34
  /**
40
- * Pauses the timer _(if it was running)_
35
+ * Pause the timer _(if it's running)_
41
36
  */
42
37
  pause(): Timer;
43
38
  /**
44
- * Restarts the timer _(if it was running)_
39
+ * Restart the timer _(or start it, if it's not running)_
45
40
  */
46
41
  restart(): Timer;
47
42
  /**
48
- * Starts the timer _(if it was stopped)_
43
+ * Start the timer _(if it's not running)_
49
44
  */
50
45
  start(): Timer;
51
46
  /**
52
- * Stops the timer _(if it was running)_
47
+ * Stop the timer _(if it's running)_
53
48
  */
54
49
  stop(): Timer;
55
50
  }
56
51
  /**
57
- * Callback that runs after the timer has finished (or is stopped)
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 IndexedCallback = (index: number) => void;
66
- export type BaseOptions = {
54
+ export type RepeatOptions = {
67
55
  /**
68
- * Interval between each callback
56
+ * Callback to be called when the timer has stopped, either manually or by completing its work
69
57
  */
70
- interval: number;
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
- * Callback to run when an error occurs _(usually a timeout)_
64
+ * The interval between each repeat
85
65
  */
86
- errorCallback?: () => void;
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: AnyCallback;
77
+ callback: () => void;
99
78
  destroyed: boolean;
100
- count?: number;
101
- elapsed?: number;
102
- frame?: number;
103
- index?: number;
104
- isRepeated: boolean;
105
- minimum: number;
79
+ elapsed: number;
80
+ frame: number | undefined;
81
+ index: number;
106
82
  paused: boolean;
107
- trace?: string;
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 WaitOptions = {} & BaseOptions & OptionsWithError;
113
- export type WhenOptions = {} & OptionsWithCount;
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 WorkType = "continue" | "pause" | "restart" | "start" | "stop";
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 {};