@oscarpalmer/timer 0.31.0 → 0.33.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/types/is.d.cts CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  declare class Timer {
4
4
  #private;
5
- protected readonly worker: WorkHandler;
6
5
  protected readonly options: TimerOptions;
7
6
  private readonly $timer;
8
7
  protected readonly state: TimerState;
@@ -22,7 +21,7 @@ declare class Timer {
22
21
  * Get the timer's origin _(if debugging is enabled)_
23
22
  */
24
23
  get trace(): string | undefined;
25
- constructor(type: TimerType, worker: WorkHandler, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
24
+ constructor(type: TimerType, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
26
25
  /**
27
26
  * Continue running the timer _(if it's paused)_
28
27
  */
@@ -67,19 +66,23 @@ export type TimerState = {
67
66
  trace: string | undefined;
68
67
  };
69
68
  export type TimerType = "repeat" | "wait" | "when";
70
- export type WhenState = {
71
- promise: Promise<void>;
72
- rejecter?: () => void;
73
- resolver?: () => void;
74
- started: boolean;
75
- timer: Timer;
76
- };
77
- export type WorkHandler = (type: WorkHandlerType, timer: WorkHandlerTimer, state: TimerState, options: TimerOptions) => Timer;
78
- export type WorkHandlerTimer = {
79
- instance: Timer;
80
- type: TimerType;
69
+ /**
70
+ * Options for a conditional timer
71
+ */
72
+ export type WhenOptions = {
73
+ /**
74
+ * How many times the timer should check the condition
75
+ */
76
+ count: number;
77
+ /**
78
+ * Then interval between each condtional check
79
+ */
80
+ interval: number;
81
+ /**
82
+ * The timeout for the timer
83
+ */
84
+ timeout: number;
81
85
  };
82
- export type WorkHandlerType = "continue" | "pause" | "restart" | "start" | "stop";
83
86
  declare class When {
84
87
  private readonly $timer;
85
88
  private readonly state;
@@ -99,7 +102,7 @@ declare class When {
99
102
  * Get the timer's origin _(if debugging is enabled)_
100
103
  */
101
104
  get trace(): string | undefined;
102
- constructor(state: WhenState);
105
+ constructor(condition: () => boolean, options?: Partial<WhenOptions>);
103
106
  /**
104
107
  * Continues the timer _(if it was paused)_
105
108
  */
@@ -2,7 +2,6 @@
2
2
 
3
3
  declare class Timer {
4
4
  #private;
5
- protected readonly worker: WorkHandler;
6
5
  protected readonly options: TimerOptions;
7
6
  private readonly $timer;
8
7
  protected readonly state: TimerState;
@@ -22,7 +21,7 @@ declare class Timer {
22
21
  * Get the timer's origin _(if debugging is enabled)_
23
22
  */
24
23
  get trace(): string | undefined;
25
- constructor(type: TimerType, worker: WorkHandler, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
24
+ constructor(type: TimerType, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
26
25
  /**
27
26
  * Continue running the timer _(if it's paused)_
28
27
  */
@@ -2,7 +2,6 @@
2
2
 
3
3
  export declare class Timer {
4
4
  #private;
5
- protected readonly worker: WorkHandler;
6
5
  protected readonly options: TimerOptions;
7
6
  private readonly $timer;
8
7
  protected readonly state: TimerState;
@@ -22,7 +21,7 @@ export declare class Timer {
22
21
  * Get the timer's origin _(if debugging is enabled)_
23
22
  */
24
23
  get trace(): string | undefined;
25
- constructor(type: TimerType, worker: WorkHandler, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
24
+ constructor(type: TimerType, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
26
25
  /**
27
26
  * Continue running the timer _(if it's paused)_
28
27
  */
@@ -84,12 +83,6 @@ export type TimerState = {
84
83
  trace: string | undefined;
85
84
  };
86
85
  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
86
  /**
94
87
  * Create a repeating timer
95
88
  */
package/types/repeat.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import './global';
1
2
  import { type RepeatOptions } from './models';
2
3
  import { Timer } from './timer';
3
4
  /**
package/types/timer.d.cts CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  export declare class Timer {
4
4
  #private;
5
- protected readonly worker: WorkHandler;
6
5
  protected readonly options: TimerOptions;
7
6
  private readonly $timer;
8
7
  protected readonly state: TimerState;
@@ -22,7 +21,7 @@ export declare class Timer {
22
21
  * Get the timer's origin _(if debugging is enabled)_
23
22
  */
24
23
  get trace(): string | undefined;
25
- constructor(type: TimerType, worker: WorkHandler, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
24
+ constructor(type: TimerType, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
26
25
  /**
27
26
  * Continue running the timer _(if it's paused)_
28
27
  */
@@ -67,11 +66,5 @@ export type TimerState = {
67
66
  trace: string | undefined;
68
67
  };
69
68
  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
69
 
77
70
  export {};
package/types/timer.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import type { TimerOptions, TimerState, TimerType, WorkHandler } from './models';
1
+ import type { TimerOptions, TimerState, TimerType } from './models';
2
2
  export declare class Timer {
3
3
  #private;
4
- protected readonly worker: WorkHandler;
5
4
  protected readonly options: TimerOptions;
6
5
  private readonly $timer;
7
6
  protected readonly state: TimerState;
@@ -21,7 +20,7 @@ export declare class Timer {
21
20
  * Get the timer's origin _(if debugging is enabled)_
22
21
  */
23
22
  get trace(): string | undefined;
24
- constructor(type: TimerType, worker: WorkHandler, state: Pick<TimerState, 'callback' | 'trace'>, options: TimerOptions, start: boolean);
23
+ constructor(type: TimerType, state: Pick<TimerState, 'callback' | 'trace'>, options: TimerOptions, start: boolean);
25
24
  /**
26
25
  * Continue running the timer _(if it's paused)_
27
26
  */
package/types/wait.d.cts CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  export declare class Timer {
4
4
  #private;
5
- protected readonly worker: WorkHandler;
6
5
  protected readonly options: TimerOptions;
7
6
  private readonly $timer;
8
7
  protected readonly state: TimerState;
@@ -22,7 +21,7 @@ export declare class Timer {
22
21
  * Get the timer's origin _(if debugging is enabled)_
23
22
  */
24
23
  get trace(): string | undefined;
25
- constructor(type: TimerType, worker: WorkHandler, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
24
+ constructor(type: TimerType, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
26
25
  /**
27
26
  * Continue running the timer _(if it's paused)_
28
27
  */
@@ -67,12 +66,6 @@ export type TimerState = {
67
66
  trace: string | undefined;
68
67
  };
69
68
  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
69
  /**
77
70
  * Create a waiting timer
78
71
  * @param callback Callback to run when the timer has finished
package/types/wait.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import './global';
1
2
  import { Timer } from './timer';
2
3
  /**
3
4
  * Create a waiting timer
package/types/when.d.cts CHANGED
@@ -1,72 +1,5 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
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;
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
3
  /**
71
4
  * Options for a conditional timer
72
5
  */
@@ -84,19 +17,6 @@ export type WhenOptions = {
84
17
  */
85
18
  timeout: number;
86
19
  };
87
- export type WhenState = {
88
- promise: Promise<void>;
89
- rejecter?: () => void;
90
- resolver?: () => void;
91
- started: boolean;
92
- timer: Timer;
93
- };
94
- export type WorkHandler = (type: WorkHandlerType, timer: WorkHandlerTimer, state: TimerState, options: TimerOptions) => Timer;
95
- export type WorkHandlerTimer = {
96
- instance: Timer;
97
- type: TimerType;
98
- };
99
- export type WorkHandlerType = "continue" | "pause" | "restart" | "start" | "stop";
100
20
  export declare class When {
101
21
  private readonly $timer;
102
22
  private readonly state;
@@ -116,7 +36,7 @@ export declare class When {
116
36
  * Get the timer's origin _(if debugging is enabled)_
117
37
  */
118
38
  get trace(): string | undefined;
119
- constructor(state: WhenState);
39
+ constructor(condition: () => boolean, options?: Partial<WhenOptions>);
120
40
  /**
121
41
  * Continues the timer _(if it was paused)_
122
42
  */
package/types/when.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { type WhenOptions, type WhenState } from './models';
1
+ import './global';
2
+ import { type WhenOptions } from './models';
2
3
  declare class When {
3
4
  private readonly $timer;
4
5
  private readonly state;
@@ -18,7 +19,7 @@ declare class When {
18
19
  * Get the timer's origin _(if debugging is enabled)_
19
20
  */
20
21
  get trace(): string | undefined;
21
- constructor(state: WhenState);
22
+ constructor(condition: () => boolean, options?: Partial<WhenOptions>);
22
23
  /**
23
24
  * Continues the timer _(if it was paused)_
24
25
  */
package/types/work.d.cts CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  declare class Timer {
4
4
  #private;
5
- protected readonly worker: WorkHandler;
6
5
  protected readonly options: TimerOptions;
7
6
  private readonly $timer;
8
7
  protected readonly state: TimerState;
@@ -22,7 +21,7 @@ declare class Timer {
22
21
  * Get the timer's origin _(if debugging is enabled)_
23
22
  */
24
23
  get trace(): string | undefined;
25
- constructor(type: TimerType, worker: WorkHandler, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
24
+ constructor(type: TimerType, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
26
25
  /**
27
26
  * Continue running the timer _(if it's paused)_
28
27
  */
@@ -67,12 +66,16 @@ export type TimerState = {
67
66
  trace: string | undefined;
68
67
  };
69
68
  export type TimerType = "repeat" | "wait" | "when";
70
- export type WorkHandler = (type: WorkHandlerType, timer: WorkHandlerTimer, state: TimerState, options: TimerOptions) => Timer;
71
69
  export type WorkHandlerTimer = {
72
70
  instance: Timer;
73
71
  type: TimerType;
74
72
  };
75
73
  export type WorkHandlerType = "continue" | "pause" | "restart" | "start" | "stop";
74
+ declare function stop$1(timer: WorkHandlerTimer, state: TimerState, options: TimerOptions): void;
76
75
  export declare function work(type: WorkHandlerType, timer: WorkHandlerTimer, state: TimerState, options: TimerOptions): Timer;
77
76
 
77
+ export {
78
+ stop$1 as stop,
79
+ };
80
+
78
81
  export {};
package/types/work.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import type { TimerOptions, TimerState, WorkHandlerTimer, WorkHandlerType } from './models';
2
2
  import type { Timer } from './timer';
3
+ export declare function stop(timer: WorkHandlerTimer, state: TimerState, options: TimerOptions): void;
3
4
  export declare function work(type: WorkHandlerType, timer: WorkHandlerTimer, state: TimerState, options: TimerOptions): Timer;