@oscarpalmer/timer 0.32.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.
@@ -187,15 +187,16 @@ function ignore(type, state) {
187
187
  (state.active ? beginTypes.has(type) : endTypes.has(type)));
188
188
  }
189
189
  function run(timer, state, options) {
190
- let start;
190
+ let last;
191
191
  return function step(now) {
192
192
  if (!state.active) {
193
193
  return;
194
194
  }
195
- start ??= now;
196
- const difference = now - start;
195
+ last ??= now;
196
+ const difference = now - last;
197
197
  state.elapsed += difference;
198
198
  state.total += difference;
199
+ last = now;
199
200
  if (options.timeout > 0 && state.total >= options.timeout) {
200
201
  options.onError?.();
201
202
  finish(timer, state, options, false);
@@ -206,7 +207,6 @@ function run(timer, state, options) {
206
207
  if (options.count > -1) {
207
208
  state.callback(state.index);
208
209
  }
209
- start = now;
210
210
  state.elapsed = 0;
211
211
  state.index += 1;
212
212
  if (options.count === -1 ||
package/dist/work.cjs CHANGED
@@ -29,15 +29,16 @@ function ignore(type, state) {
29
29
  return state.destroyed && type !== "stop" || (state.active ? constants.beginTypes.has(type) : constants.endTypes.has(type));
30
30
  }
31
31
  function run(timer, state, options) {
32
- let start;
32
+ let last;
33
33
  return function step(now) {
34
34
  if (!state.active) {
35
35
  return;
36
36
  }
37
- start ??= now;
38
- const difference = now - start;
37
+ last ??= now;
38
+ const difference = now - last;
39
39
  state.elapsed += difference;
40
40
  state.total += difference;
41
+ last = now;
41
42
  if (options.timeout > 0 && state.total >= options.timeout) {
42
43
  options.onError?.();
43
44
  finish(timer, state, options, false);
@@ -47,7 +48,6 @@ function run(timer, state, options) {
47
48
  if (options.count > -1) {
48
49
  state.callback(state.index);
49
50
  }
50
- start = now;
51
51
  state.elapsed = 0;
52
52
  state.index += 1;
53
53
  if (options.count === -1 || options.count > 0 && state.index >= options.count) {
package/dist/work.js CHANGED
@@ -25,15 +25,16 @@ function ignore(type, state) {
25
25
  return state.destroyed && type !== "stop" || (state.active ? beginTypes.has(type) : endTypes.has(type));
26
26
  }
27
27
  function run(timer, state, options) {
28
- let start;
28
+ let last;
29
29
  return function step(now) {
30
30
  if (!state.active) {
31
31
  return;
32
32
  }
33
- start ??= now;
34
- const difference = now - start;
33
+ last ??= now;
34
+ const difference = now - last;
35
35
  state.elapsed += difference;
36
36
  state.total += difference;
37
+ last = now;
37
38
  if (options.timeout > 0 && state.total >= options.timeout) {
38
39
  options.onError?.();
39
40
  finish(timer, state, options, false);
@@ -43,7 +44,6 @@ function run(timer, state, options) {
43
44
  if (options.count > -1) {
44
45
  state.callback(state.index);
45
46
  }
46
- start = now;
47
47
  state.elapsed = 0;
48
48
  state.index += 1;
49
49
  if (options.count === -1 || options.count > 0 && state.index >= options.count) {
package/package.json CHANGED
@@ -11,15 +11,15 @@
11
11
  "@biomejs/biome": "^1.9",
12
12
  "@rollup/plugin-node-resolve": "^16",
13
13
  "@rollup/plugin-typescript": "^12.1",
14
- "@types/node": "^22.15",
15
- "@vitest/coverage-istanbul": "^3.1",
14
+ "@types/node": "^24",
15
+ "@vitest/coverage-istanbul": "^3.2",
16
16
  "dts-bundle-generator": "^9.5",
17
17
  "glob": "^11",
18
18
  "jsdom": "^26.1",
19
19
  "tslib": "^2.8",
20
20
  "typescript": "^5.8",
21
21
  "vite": "^6.3",
22
- "vitest": "^3.1"
22
+ "vitest": "^3.2"
23
23
  },
24
24
  "exports": {
25
25
  ".": {
@@ -94,5 +94,5 @@
94
94
  },
95
95
  "type": "module",
96
96
  "types": "types/index.d.cts",
97
- "version": "0.32.0"
97
+ "version": "0.33.0"
98
98
  }
package/src/work.ts CHANGED
@@ -67,6 +67,7 @@ function run(
67
67
  state: TimerState,
68
68
  options: TimerOptions,
69
69
  ): (now: DOMHighResTimeStamp) => void {
70
+ let last: DOMHighResTimeStamp | undefined;
70
71
  let start: DOMHighResTimeStamp | undefined;
71
72
 
72
73
  return function step(now: DOMHighResTimeStamp): void {
@@ -74,13 +75,16 @@ function run(
74
75
  return;
75
76
  }
76
77
 
78
+ last ??= now;
77
79
  start ??= now;
78
80
 
79
- const difference = now - start;
81
+ const difference = now - last;
80
82
 
81
83
  state.elapsed += difference;
82
84
  state.total += difference;
83
85
 
86
+ last = now;
87
+
84
88
  if (options.timeout > 0 && state.total >= options.timeout) {
85
89
  options.onError?.();
86
90