worker-timers-broker 6.1.8 → 7.0.1

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.
@@ -1,4 +1,4 @@
1
1
  export const isClearResponse = (message) => {
2
- return message.error === null && typeof message.id === 'number';
2
+ return typeof message.id === 'number' && typeof message.result === 'boolean';
3
3
  };
4
4
  //# sourceMappingURL=clear-response.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"clear-response.js","sourceRoot":"","sources":["../../../src/guards/clear-response.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAuB,EAA6B,EAAE;IAClF,OAAwB,OAAQ,CAAC,KAAK,KAAK,IAAI,IAAI,OAAO,OAAO,CAAC,EAAE,KAAK,QAAQ,CAAC;AACtF,CAAC,CAAC"}
1
+ {"version":3,"file":"clear-response.js","sourceRoot":"","sources":["../../../src/guards/clear-response.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAuB,EAA6B,EAAE;IAClF,OAAO,OAAO,OAAO,CAAC,EAAE,KAAK,QAAQ,IAAI,OAAwB,OAAQ,CAAC,MAAM,KAAK,SAAS,CAAC;AACnG,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,IAAI,QAAS,MAAM;6BAiFI,MAAM;4BAaP,MAAM;wBAaV,QAAQ;uBAmCT,QAAQ;CAyBrC,CAAC"}
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,IAAI,QAAS,MAAM;6BAqFI,MAAM;4BAeP,MAAM;wBAeV,QAAQ;uBAmCT,QAAQ;CAyBrC,CAAC"}
@@ -12,6 +12,9 @@ export const load = (url) => {
12
12
  const { params: { timerId, timerType } } = data;
13
13
  if (timerType === 'interval') {
14
14
  const idOrFunc = scheduledIntervalFunctions.get(timerId);
15
+ if (typeof idOrFunc === undefined) {
16
+ throw new Error('The timer is in an undefined state.');
17
+ }
15
18
  if (typeof idOrFunc === 'number') {
16
19
  const timerIdAndTimerType = unrespondedRequests.get(idOrFunc);
17
20
  if (timerIdAndTimerType === undefined ||
@@ -20,15 +23,15 @@ export const load = (url) => {
20
23
  throw new Error('The timer is in an undefined state.');
21
24
  }
22
25
  }
23
- else if (typeof idOrFunc !== 'undefined') {
26
+ else if (typeof idOrFunc === 'function') {
24
27
  idOrFunc();
25
28
  }
26
- else {
27
- throw new Error('The timer is in an undefined state.');
28
- }
29
29
  }
30
30
  else if (timerType === 'timeout') {
31
31
  const idOrFunc = scheduledTimeoutFunctions.get(timerId);
32
+ if (typeof idOrFunc === undefined) {
33
+ throw new Error('The timer is in an undefined state.');
34
+ }
32
35
  if (typeof idOrFunc === 'number') {
33
36
  const timerIdAndTimerType = unrespondedRequests.get(idOrFunc);
34
37
  if (timerIdAndTimerType === undefined ||
@@ -37,14 +40,11 @@ export const load = (url) => {
37
40
  throw new Error('The timer is in an undefined state.');
38
41
  }
39
42
  }
40
- else if (typeof idOrFunc !== 'undefined') {
43
+ else if (typeof idOrFunc === 'function') {
41
44
  idOrFunc();
42
45
  // A timeout can be savely deleted because it is only called once.
43
46
  scheduledTimeoutFunctions.delete(timerId);
44
47
  }
45
- else {
46
- throw new Error('The timer is in an undefined state.');
47
- }
48
48
  }
49
49
  }
50
50
  else if (isClearResponse(data)) {
@@ -68,24 +68,28 @@ export const load = (url) => {
68
68
  }
69
69
  });
70
70
  const clearInterval = (timerId) => {
71
- const id = generateUniqueNumber(unrespondedRequests);
72
- unrespondedRequests.set(id, { timerId, timerType: 'interval' });
73
- scheduledIntervalFunctions.set(timerId, id);
74
- worker.postMessage({
75
- id,
76
- method: 'clear',
77
- params: { timerId, timerType: 'interval' }
78
- });
71
+ if (typeof scheduledIntervalFunctions.get(timerId) === 'function') {
72
+ const id = generateUniqueNumber(unrespondedRequests);
73
+ unrespondedRequests.set(id, { timerId, timerType: 'interval' });
74
+ scheduledIntervalFunctions.set(timerId, id);
75
+ worker.postMessage({
76
+ id,
77
+ method: 'clear',
78
+ params: { timerId, timerType: 'interval' }
79
+ });
80
+ }
79
81
  };
80
82
  const clearTimeout = (timerId) => {
81
- const id = generateUniqueNumber(unrespondedRequests);
82
- unrespondedRequests.set(id, { timerId, timerType: 'timeout' });
83
- scheduledTimeoutFunctions.set(timerId, id);
84
- worker.postMessage({
85
- id,
86
- method: 'clear',
87
- params: { timerId, timerType: 'timeout' }
88
- });
83
+ if (typeof scheduledTimeoutFunctions.get(timerId) === 'function') {
84
+ const id = generateUniqueNumber(unrespondedRequests);
85
+ unrespondedRequests.set(id, { timerId, timerType: 'timeout' });
86
+ scheduledTimeoutFunctions.set(timerId, id);
87
+ worker.postMessage({
88
+ id,
89
+ method: 'clear',
90
+ params: { timerId, timerType: 'timeout' }
91
+ });
92
+ }
89
93
  };
90
94
  const setInterval = (func, delay = 0) => {
91
95
  const timerId = generateUniqueNumber(scheduledIntervalFunctions);
@@ -98,7 +102,7 @@ export const load = (url) => {
98
102
  method: 'set',
99
103
  params: {
100
104
  delay,
101
- now: performance.now(),
105
+ now: performance.timeOrigin + performance.now(),
102
106
  timerId,
103
107
  timerType: 'interval'
104
108
  }
@@ -110,7 +114,7 @@ export const load = (url) => {
110
114
  method: 'set',
111
115
  params: {
112
116
  delay,
113
- now: performance.now(),
117
+ now: performance.timeOrigin + performance.now(),
114
118
  timerId,
115
119
  timerType: 'interval'
116
120
  }
@@ -125,7 +129,7 @@ export const load = (url) => {
125
129
  method: 'set',
126
130
  params: {
127
131
  delay,
128
- now: performance.now(),
132
+ now: performance.timeOrigin + performance.now(),
129
133
  timerId,
130
134
  timerType: 'timeout'
131
135
  }
@@ -1 +1 @@
1
- {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,q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AAM,EAAE,KAAK;YACb,MAAM,EAAE;gBACJ,KAAK;gBACL,GAAG,EAAE,WAAW,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE;gBAC/C,OAAO;gBACP,SAAS,EAAE,UAAU;aACxB;SACJ,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACnB,CAAC,CAAC;IAEF,MAAM,UAAU,GAAG,CAAC,IAAc,EAAE,KAAK,GAAG,CAAC,EAAE,EAAE;QAC7C,MAAM,OAAO,GAAG,oBAAoB,CAAC,yBAAyB,CAAC,CAAC;QAEhE,yBAAyB,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAE7C,MAAM,CAAC,WAAW,CAAmB;YACjC,EAAE,EAAE,IAAI;YACR,MAAM,EAAE,KAAK;YACb,MAAM,EAAE;gBACJ,KAAK;gBACL,GAAG,EAAE,WAAW,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE;gBAC/C,OAAO;gBACP,SAAS,EAAE,SAAS;aACvB;SACJ,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO;QACH,aAAa;QACb,YAAY;QACZ,WAAW;QACX,UAAU;KACb,CAAC;AACN,CAAC,CAAC"}
@@ -1,15 +1,15 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fast-unique-numbers')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'fast-unique-numbers'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.workerTimersBroker = {}, global.fastUniqueNumbers));
5
- })(this, (function (exports, fastUniqueNumbers) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/typeof'), require('fast-unique-numbers')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/typeof', 'fast-unique-numbers'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.workerTimersBroker = {}, global._typeof, global.fastUniqueNumbers));
5
+ })(this, (function (exports, _typeof, fastUniqueNumbers) { 'use strict';
6
6
 
7
7
  var isCallNotification = function isCallNotification(message) {
8
8
  return message.method !== undefined && message.method === 'call';
9
9
  };
10
10
 
11
11
  var isClearResponse = function isClearResponse(message) {
12
- return message.error === null && typeof message.id === 'number';
12
+ return typeof message.id === 'number' && typeof message.result === 'boolean';
13
13
  };
14
14
 
15
15
  var load = function load(url) {
@@ -26,29 +26,31 @@
26
26
  timerType = _data$params.timerType;
27
27
  if (timerType === 'interval') {
28
28
  var idOrFunc = scheduledIntervalFunctions.get(timerId);
29
+ if (_typeof(idOrFunc) === undefined) {
30
+ throw new Error('The timer is in an undefined state.');
31
+ }
29
32
  if (typeof idOrFunc === 'number') {
30
33
  var timerIdAndTimerType = unrespondedRequests.get(idOrFunc);
31
34
  if (timerIdAndTimerType === undefined || timerIdAndTimerType.timerId !== timerId || timerIdAndTimerType.timerType !== timerType) {
32
35
  throw new Error('The timer is in an undefined state.');
33
36
  }
34
- } else if (typeof idOrFunc !== 'undefined') {
37
+ } else if (typeof idOrFunc === 'function') {
35
38
  idOrFunc();
36
- } else {
37
- throw new Error('The timer is in an undefined state.');
38
39
  }
39
40
  } else if (timerType === 'timeout') {
40
41
  var _idOrFunc = scheduledTimeoutFunctions.get(timerId);
42
+ if (_typeof(_idOrFunc) === undefined) {
43
+ throw new Error('The timer is in an undefined state.');
44
+ }
41
45
  if (typeof _idOrFunc === 'number') {
42
46
  var _timerIdAndTimerType = unrespondedRequests.get(_idOrFunc);
43
47
  if (_timerIdAndTimerType === undefined || _timerIdAndTimerType.timerId !== timerId || _timerIdAndTimerType.timerType !== timerType) {
44
48
  throw new Error('The timer is in an undefined state.');
45
49
  }
46
- } else if (typeof _idOrFunc !== 'undefined') {
50
+ } else if (typeof _idOrFunc === 'function') {
47
51
  _idOrFunc();
48
52
  // A timeout can be savely deleted because it is only called once.
49
53
  scheduledTimeoutFunctions["delete"](timerId);
50
- } else {
51
- throw new Error('The timer is in an undefined state.');
52
54
  }
53
55
  }
54
56
  } else if (isClearResponse(data)) {
@@ -71,36 +73,40 @@
71
73
  }
72
74
  });
73
75
  var clearInterval = function clearInterval(timerId) {
74
- var id = fastUniqueNumbers.generateUniqueNumber(unrespondedRequests);
75
- unrespondedRequests.set(id, {
76
- timerId: timerId,
77
- timerType: 'interval'
78
- });
79
- scheduledIntervalFunctions.set(timerId, id);
80
- worker.postMessage({
81
- id: id,
82
- method: 'clear',
83
- params: {
76
+ if (typeof scheduledIntervalFunctions.get(timerId) === 'function') {
77
+ var id = fastUniqueNumbers.generateUniqueNumber(unrespondedRequests);
78
+ unrespondedRequests.set(id, {
84
79
  timerId: timerId,
85
80
  timerType: 'interval'
86
- }
87
- });
81
+ });
82
+ scheduledIntervalFunctions.set(timerId, id);
83
+ worker.postMessage({
84
+ id: id,
85
+ method: 'clear',
86
+ params: {
87
+ timerId: timerId,
88
+ timerType: 'interval'
89
+ }
90
+ });
91
+ }
88
92
  };
89
93
  var clearTimeout = function clearTimeout(timerId) {
90
- var id = fastUniqueNumbers.generateUniqueNumber(unrespondedRequests);
91
- unrespondedRequests.set(id, {
92
- timerId: timerId,
93
- timerType: 'timeout'
94
- });
95
- scheduledTimeoutFunctions.set(timerId, id);
96
- worker.postMessage({
97
- id: id,
98
- method: 'clear',
99
- params: {
94
+ if (typeof scheduledTimeoutFunctions.get(timerId) === 'function') {
95
+ var id = fastUniqueNumbers.generateUniqueNumber(unrespondedRequests);
96
+ unrespondedRequests.set(id, {
100
97
  timerId: timerId,
101
98
  timerType: 'timeout'
102
- }
103
- });
99
+ });
100
+ scheduledTimeoutFunctions.set(timerId, id);
101
+ worker.postMessage({
102
+ id: id,
103
+ method: 'clear',
104
+ params: {
105
+ timerId: timerId,
106
+ timerType: 'timeout'
107
+ }
108
+ });
109
+ }
104
110
  };
105
111
  var setInterval = function setInterval(func) {
106
112
  var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
@@ -114,7 +120,7 @@
114
120
  method: 'set',
115
121
  params: {
116
122
  delay: delay,
117
- now: performance.now(),
123
+ now: performance.timeOrigin + performance.now(),
118
124
  timerId: timerId,
119
125
  timerType: 'interval'
120
126
  }
@@ -126,7 +132,7 @@
126
132
  method: 'set',
127
133
  params: {
128
134
  delay: delay,
129
- now: performance.now(),
135
+ now: performance.timeOrigin + performance.now(),
130
136
  timerId: timerId,
131
137
  timerType: 'interval'
132
138
  }
@@ -142,7 +148,7 @@
142
148
  method: 'set',
143
149
  params: {
144
150
  delay: delay,
145
- now: performance.now(),
151
+ now: performance.timeOrigin + performance.now(),
146
152
  timerId: timerId,
147
153
  timerType: 'timeout'
148
154
  }
package/package.json CHANGED
@@ -10,9 +10,9 @@
10
10
  },
11
11
  "dependencies": {
12
12
  "@babel/runtime": "^7.24.5",
13
- "fast-unique-numbers": "^8.0.13",
13
+ "fast-unique-numbers": "^9.0.5",
14
14
  "tslib": "^2.6.2",
15
- "worker-timers-worker": "^7.0.71"
15
+ "worker-timers-worker": "^8.0.0"
16
16
  },
17
17
  "description": "The broker which is used by the worker-timers package.",
18
18
  "devDependencies": {
@@ -27,7 +27,7 @@
27
27
  "commitizen": "^4.3.0",
28
28
  "cz-conventional-changelog": "^3.3.0",
29
29
  "eslint": "^8.57.0",
30
- "eslint-config-holy-grail": "^59.0.8",
30
+ "eslint-config-holy-grail": "^59.0.10",
31
31
  "grunt": "^1.6.1",
32
32
  "grunt-cli": "^1.4.3",
33
33
  "grunt-sh": "^0.2.1",
@@ -40,13 +40,13 @@
40
40
  "karma-sinon-chai": "^2.0.2",
41
41
  "karma-webkit-launcher": "^2.4.0",
42
42
  "karma-webpack": "^5.0.1",
43
- "lint-staged": "^15.2.2",
43
+ "lint-staged": "^15.2.4",
44
44
  "load-grunt-config": "^4.0.1",
45
45
  "mocha": "^10.4.0",
46
46
  "prettier": "^3.2.5",
47
- "rimraf": "^5.0.5",
47
+ "rimraf": "^5.0.7",
48
48
  "rollup": "^4.17.2",
49
- "sinon": "^17.0.1",
49
+ "sinon": "^17.0.2",
50
50
  "sinon-chai": "^3.7.0",
51
51
  "ts-loader": "^9.5.1",
52
52
  "tsconfig-holy-grail": "^15.0.1",
@@ -80,5 +80,5 @@
80
80
  "test": "grunt lint && grunt test"
81
81
  },
82
82
  "types": "build/es2019/module.d.ts",
83
- "version": "6.1.8"
83
+ "version": "7.0.1"
84
84
  }
@@ -1,5 +1,5 @@
1
1
  import { IClearResponse, TWorkerMessage } from 'worker-timers-worker';
2
2
 
3
3
  export const isClearResponse = (message: TWorkerMessage): message is IClearResponse => {
4
- return (<IClearResponse>message).error === null && typeof message.id === 'number';
4
+ return typeof message.id === 'number' && typeof (<IClearResponse>message).result === 'boolean';
5
5
  };
package/src/module.ts CHANGED
@@ -20,6 +20,10 @@ export const load = (url: string) => {
20
20
  if (timerType === 'interval') {
21
21
  const idOrFunc = scheduledIntervalFunctions.get(timerId);
22
22
 
23
+ if (typeof idOrFunc === undefined) {
24
+ throw new Error('The timer is in an undefined state.');
25
+ }
26
+
23
27
  if (typeof idOrFunc === 'number') {
24
28
  const timerIdAndTimerType = unrespondedRequests.get(idOrFunc);
25
29
 
@@ -30,14 +34,16 @@ export const load = (url: string) => {
30
34
  ) {
31
35
  throw new Error('The timer is in an undefined state.');
32
36
  }
33
- } else if (typeof idOrFunc !== 'undefined') {
37
+ } else if (typeof idOrFunc === 'function') {
34
38
  idOrFunc();
35
- } else {
36
- throw new Error('The timer is in an undefined state.');
37
39
  }
38
40
  } else if (timerType === 'timeout') {
39
41
  const idOrFunc = scheduledTimeoutFunctions.get(timerId);
40
42
 
43
+ if (typeof idOrFunc === undefined) {
44
+ throw new Error('The timer is in an undefined state.');
45
+ }
46
+
41
47
  if (typeof idOrFunc === 'number') {
42
48
  const timerIdAndTimerType = unrespondedRequests.get(idOrFunc);
43
49
 
@@ -48,13 +54,11 @@ export const load = (url: string) => {
48
54
  ) {
49
55
  throw new Error('The timer is in an undefined state.');
50
56
  }
51
- } else if (typeof idOrFunc !== 'undefined') {
57
+ } else if (typeof idOrFunc === 'function') {
52
58
  idOrFunc();
53
59
 
54
60
  // A timeout can be savely deleted because it is only called once.
55
61
  scheduledTimeoutFunctions.delete(timerId);
56
- } else {
57
- throw new Error('The timer is in an undefined state.');
58
62
  }
59
63
  }
60
64
  } else if (isClearResponse(data)) {
@@ -85,29 +89,33 @@ export const load = (url: string) => {
85
89
  });
86
90
 
87
91
  const clearInterval = (timerId: number) => {
88
- const id = generateUniqueNumber(unrespondedRequests);
92
+ if (typeof scheduledIntervalFunctions.get(timerId) === 'function') {
93
+ const id = generateUniqueNumber(unrespondedRequests);
89
94
 
90
- unrespondedRequests.set(id, { timerId, timerType: 'interval' });
91
- scheduledIntervalFunctions.set(timerId, id);
95
+ unrespondedRequests.set(id, { timerId, timerType: 'interval' });
96
+ scheduledIntervalFunctions.set(timerId, id);
92
97
 
93
- worker.postMessage(<IClearRequest>{
94
- id,
95
- method: 'clear',
96
- params: { timerId, timerType: 'interval' }
97
- });
98
+ worker.postMessage(<IClearRequest>{
99
+ id,
100
+ method: 'clear',
101
+ params: { timerId, timerType: 'interval' }
102
+ });
103
+ }
98
104
  };
99
105
 
100
106
  const clearTimeout = (timerId: number) => {
101
- const id = generateUniqueNumber(unrespondedRequests);
107
+ if (typeof scheduledTimeoutFunctions.get(timerId) === 'function') {
108
+ const id = generateUniqueNumber(unrespondedRequests);
102
109
 
103
- unrespondedRequests.set(id, { timerId, timerType: 'timeout' });
104
- scheduledTimeoutFunctions.set(timerId, id);
110
+ unrespondedRequests.set(id, { timerId, timerType: 'timeout' });
111
+ scheduledTimeoutFunctions.set(timerId, id);
105
112
 
106
- worker.postMessage(<IClearRequest>{
107
- id,
108
- method: 'clear',
109
- params: { timerId, timerType: 'timeout' }
110
- });
113
+ worker.postMessage(<IClearRequest>{
114
+ id,
115
+ method: 'clear',
116
+ params: { timerId, timerType: 'timeout' }
117
+ });
118
+ }
111
119
  };
112
120
 
113
121
  const setInterval = (func: Function, delay = 0) => {
@@ -123,7 +131,7 @@ export const load = (url: string) => {
123
131
  method: 'set',
124
132
  params: {
125
133
  delay,
126
- now: performance.now(),
134
+ now: performance.timeOrigin + performance.now(),
127
135
  timerId,
128
136
  timerType: 'interval'
129
137
  }
@@ -136,7 +144,7 @@ export const load = (url: string) => {
136
144
  method: 'set',
137
145
  params: {
138
146
  delay,
139
- now: performance.now(),
147
+ now: performance.timeOrigin + performance.now(),
140
148
  timerId,
141
149
  timerType: 'interval'
142
150
  }
@@ -155,7 +163,7 @@ export const load = (url: string) => {
155
163
  method: 'set',
156
164
  params: {
157
165
  delay,
158
- now: performance.now(),
166
+ now: performance.timeOrigin + performance.now(),
159
167
  timerId,
160
168
  timerType: 'timeout'
161
169
  }