@oscarpalmer/timer 0.32.0 → 0.34.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/wait.cjs CHANGED
@@ -1,29 +1,18 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const constants = require('./constants.cjs');
6
- const get = require('./get.cjs');
7
- require('./global.cjs');
8
- const models = require('./models.cjs');
9
- const timer = require('./timer.cjs');
10
-
1
+ const require_constants = require("./constants.cjs");
2
+ const require_get = require("./get.cjs");
3
+ require("./global.cjs");
4
+ const require_models = require("./models.cjs");
5
+ const require_timer = require("./timer.cjs");
11
6
  function wait(callback, time) {
12
- return new timer.Timer(
13
- "wait",
14
- {
15
- callback: get.getCallback(callback),
16
- trace: new models.TimerTrace().stack
17
- },
18
- {
19
- onAfter: void 0,
20
- onError: void 0,
21
- count: -1,
22
- interval: get.getValidNumber(time, constants.milliseconds),
23
- timeout: 0
24
- },
25
- true
26
- );
7
+ return new require_timer.Timer(require_constants.TYPE_WAIT, {
8
+ callback: require_get.getCallback(callback),
9
+ trace: new require_models.TimerTrace().stack
10
+ }, {
11
+ onAfter: void 0,
12
+ onError: void 0,
13
+ count: -1,
14
+ interval: require_get.getValidNumber(time, require_constants.milliseconds),
15
+ timeout: 0
16
+ }, true);
27
17
  }
28
-
29
18
  exports.wait = wait;
package/dist/wait.js CHANGED
@@ -1,25 +1,18 @@
1
- import { milliseconds } from './constants.js';
2
- import { getCallback, getValidNumber } from './get.js';
3
- import './global.js';
4
- import { TimerTrace } from './models.js';
5
- import { Timer } from './timer.js';
6
-
1
+ import { TYPE_WAIT, milliseconds } from "./constants.js";
2
+ import { getCallback, getValidNumber } from "./get.js";
3
+ import "./global.js";
4
+ import { TimerTrace } from "./models.js";
5
+ import { Timer } from "./timer.js";
7
6
  function wait(callback, time) {
8
- return new Timer(
9
- "wait",
10
- {
11
- callback: getCallback(callback),
12
- trace: new TimerTrace().stack
13
- },
14
- {
15
- onAfter: void 0,
16
- onError: void 0,
17
- count: -1,
18
- interval: getValidNumber(time, milliseconds),
19
- timeout: 0
20
- },
21
- true
22
- );
7
+ return new Timer(TYPE_WAIT, {
8
+ callback: getCallback(callback),
9
+ trace: new TimerTrace().stack
10
+ }, {
11
+ onAfter: void 0,
12
+ onError: void 0,
13
+ count: -1,
14
+ interval: getValidNumber(time, milliseconds),
15
+ timeout: 0
16
+ }, true);
23
17
  }
24
-
25
18
  export { wait };
package/dist/when.cjs CHANGED
@@ -1,140 +1,95 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const _function = require('@oscarpalmer/atoms/function');
6
- const constants = require('./constants.cjs');
7
- const get = require('./get.cjs');
8
- require('./global.cjs');
9
- const models = require('./models.cjs');
10
- const timer = require('./timer.cjs');
11
-
12
- class When {
13
- $timer = "when";
14
- state = {
15
- promise: void 0,
16
- rejecter: void 0,
17
- resolver: void 0,
18
- started: false,
19
- timer: void 0
20
- };
21
- /**
22
- * Is the timer active?
23
- */
24
- get active() {
25
- return this.state.timer?.active ?? false;
26
- }
27
- /**
28
- * Is the timer destroyed?
29
- */
30
- get destroyed() {
31
- return this.state.timer == null;
32
- }
33
- /**
34
- * Is the timer paused?
35
- */
36
- get paused() {
37
- return this.state.timer?.paused ?? false;
38
- }
39
- /**
40
- * Get the timer's origin _(if debugging is enabled)_
41
- */
42
- get trace() {
43
- return globalThis._oscarpalmer_timer_debug ?? false ? this.state.timer?.trace : void 0;
44
- }
45
- constructor(condition, options) {
46
- const { state } = this;
47
- state.promise = new Promise((resolve, reject) => {
48
- state.resolver = resolve;
49
- state.rejecter = reject;
50
- });
51
- let result = false;
52
- this.state.timer = new timer.Timer(
53
- "when",
54
- {
55
- callback() {
56
- try {
57
- if (condition()) {
58
- result = true;
59
- state.timer.stop();
60
- }
61
- } catch {
62
- state.timer.stop();
63
- }
64
- },
65
- trace: new models.TimerTrace().stack
66
- },
67
- {
68
- onAfter: () => {
69
- if (result) {
70
- state.resolver?.();
71
- } else {
72
- state.rejecter?.();
73
- }
74
- this.destroy();
75
- },
76
- onError: () => {
77
- state.rejecter?.();
78
- this.destroy();
79
- },
80
- count: get.getValidNumber(options?.count),
81
- interval: get.getValidNumber(options?.interval, constants.milliseconds),
82
- timeout: get.getValidNumber(options?.timeout)
83
- },
84
- false
85
- );
86
- }
87
- /**
88
- * Continues the timer _(if it was paused)_
89
- */
90
- continue() {
91
- this.state.timer?.continue();
92
- return this;
93
- }
94
- /**
95
- * Destroys the timer _(and stops it,if it was running)_
96
- */
97
- destroy() {
98
- const { state } = this;
99
- state.timer?.destroy();
100
- state.promise = void 0;
101
- state.resolver = _function.noop;
102
- state.rejecter = _function.noop;
103
- state.timer = void 0;
104
- }
105
- /**
106
- * Pauses the timer _(if it was running)_
107
- */
108
- pause() {
109
- this.state.timer?.pause();
110
- return this;
111
- }
112
- /**
113
- * Stops the timer _(if it was running)_
114
- */
115
- stop() {
116
- this.state.timer?.stop();
117
- return this;
118
- }
119
- /**
120
- * Starts the timer and returns a promise that resolves when the condition is met
121
- */
122
- // biome-ignore lint/suspicious/noThenProperty: returning a promise-like object, so it's ok ;)
123
- then(resolve, reject) {
124
- const { state } = this;
125
- if (state.timer == null) {
126
- throw new Error(constants.destroyedMessage);
127
- }
128
- if (state.started) {
129
- throw new Error(constants.startedMessage);
130
- }
131
- state.started = true;
132
- state.timer.start();
133
- return state.promise.then(resolve ?? _function.noop, reject ?? _function.noop);
134
- }
135
- }
1
+ const require_rolldown_runtime = require("./rolldown_runtime.cjs");
2
+ const require_constants = require("./constants.cjs");
3
+ const require_get = require("./get.cjs");
4
+ require("./global.cjs");
5
+ const require_models = require("./models.cjs");
6
+ const require_timer = require("./timer.cjs");
7
+ const __oscarpalmer_atoms_function = require_rolldown_runtime.__toESM(require("@oscarpalmer/atoms/function"));
8
+ var When = class {
9
+ $timer = require_constants.TYPE_WHEN;
10
+ state = {
11
+ promise: void 0,
12
+ rejecter: void 0,
13
+ resolver: void 0,
14
+ started: false,
15
+ timer: void 0
16
+ };
17
+ get active() {
18
+ return this.state.timer?.active ?? false;
19
+ }
20
+ get destroyed() {
21
+ return this.state.timer == null;
22
+ }
23
+ get paused() {
24
+ return this.state.timer?.paused ?? false;
25
+ }
26
+ get trace() {
27
+ return globalThis._oscarpalmer_timer_debug ?? false ? this.state.timer?.trace : void 0;
28
+ }
29
+ constructor(condition, options) {
30
+ const { state } = this;
31
+ state.promise = new Promise((resolve, reject) => {
32
+ state.resolver = resolve;
33
+ state.rejecter = reject;
34
+ });
35
+ let result = false;
36
+ this.state.timer = new require_timer.Timer(require_constants.TYPE_WHEN, {
37
+ callback() {
38
+ try {
39
+ if (condition()) {
40
+ result = true;
41
+ state.timer.stop();
42
+ }
43
+ } catch {
44
+ state.timer.stop();
45
+ }
46
+ },
47
+ trace: new require_models.TimerTrace().stack
48
+ }, {
49
+ onAfter: () => {
50
+ if (result) state.resolver?.();
51
+ else state.rejecter?.();
52
+ this.destroy();
53
+ },
54
+ onError: () => {
55
+ state.rejecter?.();
56
+ this.destroy();
57
+ },
58
+ count: require_get.getValidNumber(options?.count),
59
+ interval: require_get.getValidNumber(options?.interval, require_constants.milliseconds),
60
+ timeout: require_get.getValidNumber(options?.timeout)
61
+ }, false);
62
+ }
63
+ continue() {
64
+ this.state.timer?.continue();
65
+ return this;
66
+ }
67
+ destroy() {
68
+ const { state } = this;
69
+ state.timer?.destroy();
70
+ state.promise = void 0;
71
+ state.resolver = __oscarpalmer_atoms_function.noop;
72
+ state.rejecter = __oscarpalmer_atoms_function.noop;
73
+ state.timer = void 0;
74
+ }
75
+ pause() {
76
+ this.state.timer?.pause();
77
+ return this;
78
+ }
79
+ stop() {
80
+ this.state.timer?.stop();
81
+ return this;
82
+ }
83
+ then(resolve, reject) {
84
+ const { state } = this;
85
+ if (state.timer == null) throw new Error(require_constants.destroyedMessage);
86
+ if (state.started) throw new Error(require_constants.startedMessage);
87
+ state.started = true;
88
+ state.timer.start();
89
+ return state.promise.then(resolve ?? __oscarpalmer_atoms_function.noop, reject ?? __oscarpalmer_atoms_function.noop);
90
+ }
91
+ };
136
92
  function when(condition, options) {
137
- return new When(condition, options);
93
+ return new When(condition, options);
138
94
  }
139
-
140
95
  exports.when = when;
package/dist/when.js CHANGED
@@ -1,136 +1,94 @@
1
- import { noop } from '@oscarpalmer/atoms/function';
2
- import { milliseconds, destroyedMessage, startedMessage } from './constants.js';
3
- import { getValidNumber } from './get.js';
4
- import './global.js';
5
- import { TimerTrace } from './models.js';
6
- import { Timer } from './timer.js';
7
-
8
- class When {
9
- $timer = "when";
10
- state = {
11
- promise: void 0,
12
- rejecter: void 0,
13
- resolver: void 0,
14
- started: false,
15
- timer: void 0
16
- };
17
- /**
18
- * Is the timer active?
19
- */
20
- get active() {
21
- return this.state.timer?.active ?? false;
22
- }
23
- /**
24
- * Is the timer destroyed?
25
- */
26
- get destroyed() {
27
- return this.state.timer == null;
28
- }
29
- /**
30
- * Is the timer paused?
31
- */
32
- get paused() {
33
- return this.state.timer?.paused ?? false;
34
- }
35
- /**
36
- * Get the timer's origin _(if debugging is enabled)_
37
- */
38
- get trace() {
39
- return globalThis._oscarpalmer_timer_debug ?? false ? this.state.timer?.trace : void 0;
40
- }
41
- constructor(condition, options) {
42
- const { state } = this;
43
- state.promise = new Promise((resolve, reject) => {
44
- state.resolver = resolve;
45
- state.rejecter = reject;
46
- });
47
- let result = false;
48
- this.state.timer = new Timer(
49
- "when",
50
- {
51
- callback() {
52
- try {
53
- if (condition()) {
54
- result = true;
55
- state.timer.stop();
56
- }
57
- } catch {
58
- state.timer.stop();
59
- }
60
- },
61
- trace: new TimerTrace().stack
62
- },
63
- {
64
- onAfter: () => {
65
- if (result) {
66
- state.resolver?.();
67
- } else {
68
- state.rejecter?.();
69
- }
70
- this.destroy();
71
- },
72
- onError: () => {
73
- state.rejecter?.();
74
- this.destroy();
75
- },
76
- count: getValidNumber(options?.count),
77
- interval: getValidNumber(options?.interval, milliseconds),
78
- timeout: getValidNumber(options?.timeout)
79
- },
80
- false
81
- );
82
- }
83
- /**
84
- * Continues the timer _(if it was paused)_
85
- */
86
- continue() {
87
- this.state.timer?.continue();
88
- return this;
89
- }
90
- /**
91
- * Destroys the timer _(and stops it,if it was running)_
92
- */
93
- destroy() {
94
- const { state } = this;
95
- state.timer?.destroy();
96
- state.promise = void 0;
97
- state.resolver = noop;
98
- state.rejecter = noop;
99
- state.timer = void 0;
100
- }
101
- /**
102
- * Pauses the timer _(if it was running)_
103
- */
104
- pause() {
105
- this.state.timer?.pause();
106
- return this;
107
- }
108
- /**
109
- * Stops the timer _(if it was running)_
110
- */
111
- stop() {
112
- this.state.timer?.stop();
113
- return this;
114
- }
115
- /**
116
- * Starts the timer and returns a promise that resolves when the condition is met
117
- */
118
- // biome-ignore lint/suspicious/noThenProperty: returning a promise-like object, so it's ok ;)
119
- then(resolve, reject) {
120
- const { state } = this;
121
- if (state.timer == null) {
122
- throw new Error(destroyedMessage);
123
- }
124
- if (state.started) {
125
- throw new Error(startedMessage);
126
- }
127
- state.started = true;
128
- state.timer.start();
129
- return state.promise.then(resolve ?? noop, reject ?? noop);
130
- }
131
- }
1
+ import { TYPE_WHEN, destroyedMessage, milliseconds, startedMessage } from "./constants.js";
2
+ import { getValidNumber } from "./get.js";
3
+ import "./global.js";
4
+ import { TimerTrace } from "./models.js";
5
+ import { Timer } from "./timer.js";
6
+ import { noop } from "@oscarpalmer/atoms/function";
7
+ var When = class {
8
+ $timer = TYPE_WHEN;
9
+ state = {
10
+ promise: void 0,
11
+ rejecter: void 0,
12
+ resolver: void 0,
13
+ started: false,
14
+ timer: void 0
15
+ };
16
+ get active() {
17
+ return this.state.timer?.active ?? false;
18
+ }
19
+ get destroyed() {
20
+ return this.state.timer == null;
21
+ }
22
+ get paused() {
23
+ return this.state.timer?.paused ?? false;
24
+ }
25
+ get trace() {
26
+ return globalThis._oscarpalmer_timer_debug ?? false ? this.state.timer?.trace : void 0;
27
+ }
28
+ constructor(condition, options) {
29
+ const { state } = this;
30
+ state.promise = new Promise((resolve, reject) => {
31
+ state.resolver = resolve;
32
+ state.rejecter = reject;
33
+ });
34
+ let result = false;
35
+ this.state.timer = new Timer(TYPE_WHEN, {
36
+ callback() {
37
+ try {
38
+ if (condition()) {
39
+ result = true;
40
+ state.timer.stop();
41
+ }
42
+ } catch {
43
+ state.timer.stop();
44
+ }
45
+ },
46
+ trace: new TimerTrace().stack
47
+ }, {
48
+ onAfter: () => {
49
+ if (result) state.resolver?.();
50
+ else state.rejecter?.();
51
+ this.destroy();
52
+ },
53
+ onError: () => {
54
+ state.rejecter?.();
55
+ this.destroy();
56
+ },
57
+ count: getValidNumber(options?.count),
58
+ interval: getValidNumber(options?.interval, milliseconds),
59
+ timeout: getValidNumber(options?.timeout)
60
+ }, false);
61
+ }
62
+ continue() {
63
+ this.state.timer?.continue();
64
+ return this;
65
+ }
66
+ destroy() {
67
+ const { state } = this;
68
+ state.timer?.destroy();
69
+ state.promise = void 0;
70
+ state.resolver = noop;
71
+ state.rejecter = noop;
72
+ state.timer = void 0;
73
+ }
74
+ pause() {
75
+ this.state.timer?.pause();
76
+ return this;
77
+ }
78
+ stop() {
79
+ this.state.timer?.stop();
80
+ return this;
81
+ }
82
+ then(resolve, reject) {
83
+ const { state } = this;
84
+ if (state.timer == null) throw new Error(destroyedMessage);
85
+ if (state.started) throw new Error(startedMessage);
86
+ state.started = true;
87
+ state.timer.start();
88
+ return state.promise.then(resolve ?? noop, reject ?? noop);
89
+ }
90
+ };
132
91
  function when(condition, options) {
133
- return new When(condition, options);
92
+ return new When(condition, options);
134
93
  }
135
-
136
94
  export { when };