worker-timers-broker 7.0.0 → 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.
- package/build/es2019/guards/clear-response.js +1 -1
- package/build/es2019/guards/clear-response.js.map +1 -1
- package/build/es2019/module.d.ts.map +1 -1
- package/build/es2019/module.js +29 -31
- package/build/es2019/module.js.map +1 -1
- package/build/es5/bundle.js +44 -44
- package/package.json +3 -3
- package/src/guards/clear-response.ts +1 -1
- package/src/module.ts +33 -33
|
@@ -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,
|
|
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;
|
|
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"}
|
package/build/es2019/module.js
CHANGED
|
@@ -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
|
|
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
|
|
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,30 +68,28 @@ export const load = (url) => {
|
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
const clearInterval = (timerId) => {
|
|
71
|
-
if (typeof scheduledIntervalFunctions.get(timerId)
|
|
72
|
-
|
|
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
|
+
});
|
|
73
80
|
}
|
|
74
|
-
const id = generateUniqueNumber(unrespondedRequests);
|
|
75
|
-
unrespondedRequests.set(id, { timerId, timerType: 'interval' });
|
|
76
|
-
scheduledIntervalFunctions.set(timerId, id);
|
|
77
|
-
worker.postMessage({
|
|
78
|
-
id,
|
|
79
|
-
method: 'clear',
|
|
80
|
-
params: { timerId, timerType: 'interval' }
|
|
81
|
-
});
|
|
82
81
|
};
|
|
83
82
|
const clearTimeout = (timerId) => {
|
|
84
|
-
if (typeof scheduledTimeoutFunctions.get(timerId)
|
|
85
|
-
|
|
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
|
+
});
|
|
86
92
|
}
|
|
87
|
-
const id = generateUniqueNumber(unrespondedRequests);
|
|
88
|
-
unrespondedRequests.set(id, { timerId, timerType: 'timeout' });
|
|
89
|
-
scheduledTimeoutFunctions.set(timerId, id);
|
|
90
|
-
worker.postMessage({
|
|
91
|
-
id,
|
|
92
|
-
method: 'clear',
|
|
93
|
-
params: { timerId, timerType: 'timeout' }
|
|
94
|
-
});
|
|
95
93
|
};
|
|
96
94
|
const setInterval = (func, delay = 0) => {
|
|
97
95
|
const timerId = generateUniqueNumber(scheduledIntervalFunctions);
|
|
@@ -104,7 +102,7 @@ export const load = (url) => {
|
|
|
104
102
|
method: 'set',
|
|
105
103
|
params: {
|
|
106
104
|
delay,
|
|
107
|
-
now: performance.now(),
|
|
105
|
+
now: performance.timeOrigin + performance.now(),
|
|
108
106
|
timerId,
|
|
109
107
|
timerType: 'interval'
|
|
110
108
|
}
|
|
@@ -116,7 +114,7 @@ export const load = (url) => {
|
|
|
116
114
|
method: 'set',
|
|
117
115
|
params: {
|
|
118
116
|
delay,
|
|
119
|
-
now: performance.now(),
|
|
117
|
+
now: performance.timeOrigin + performance.now(),
|
|
120
118
|
timerId,
|
|
121
119
|
timerType: 'interval'
|
|
122
120
|
}
|
|
@@ -131,7 +129,7 @@ export const load = (url) => {
|
|
|
131
129
|
method: 'set',
|
|
132
130
|
params: {
|
|
133
131
|
delay,
|
|
134
|
-
now: performance.now(),
|
|
132
|
+
now: performance.timeOrigin + performance.now(),
|
|
135
133
|
timerId,
|
|
136
134
|
timerType: 'timeout'
|
|
137
135
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,EAAE;IAChC,2GAA2G;IAC3G,MAAM,0BAA0B,GAAmC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,+BAA+B;IAC5H,MAAM,yBAAyB,GAAmC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AM,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"}
|
package/build/es5/bundle.js
CHANGED
|
@@ -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.
|
|
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
|
|
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
|
|
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,42 +73,40 @@
|
|
|
71
73
|
}
|
|
72
74
|
});
|
|
73
75
|
var clearInterval = function clearInterval(timerId) {
|
|
74
|
-
if (typeof scheduledIntervalFunctions.get(timerId)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var id = fastUniqueNumbers.generateUniqueNumber(unrespondedRequests);
|
|
78
|
-
unrespondedRequests.set(id, {
|
|
79
|
-
timerId: timerId,
|
|
80
|
-
timerType: 'interval'
|
|
81
|
-
});
|
|
82
|
-
scheduledIntervalFunctions.set(timerId, id);
|
|
83
|
-
worker.postMessage({
|
|
84
|
-
id: id,
|
|
85
|
-
method: 'clear',
|
|
86
|
-
params: {
|
|
76
|
+
if (typeof scheduledIntervalFunctions.get(timerId) === 'function') {
|
|
77
|
+
var id = fastUniqueNumbers.generateUniqueNumber(unrespondedRequests);
|
|
78
|
+
unrespondedRequests.set(id, {
|
|
87
79
|
timerId: timerId,
|
|
88
80
|
timerType: 'interval'
|
|
89
|
-
}
|
|
90
|
-
|
|
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
|
+
}
|
|
91
92
|
};
|
|
92
93
|
var clearTimeout = function clearTimeout(timerId) {
|
|
93
|
-
if (typeof scheduledTimeoutFunctions.get(timerId)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var id = fastUniqueNumbers.generateUniqueNumber(unrespondedRequests);
|
|
97
|
-
unrespondedRequests.set(id, {
|
|
98
|
-
timerId: timerId,
|
|
99
|
-
timerType: 'timeout'
|
|
100
|
-
});
|
|
101
|
-
scheduledTimeoutFunctions.set(timerId, id);
|
|
102
|
-
worker.postMessage({
|
|
103
|
-
id: id,
|
|
104
|
-
method: 'clear',
|
|
105
|
-
params: {
|
|
94
|
+
if (typeof scheduledTimeoutFunctions.get(timerId) === 'function') {
|
|
95
|
+
var id = fastUniqueNumbers.generateUniqueNumber(unrespondedRequests);
|
|
96
|
+
unrespondedRequests.set(id, {
|
|
106
97
|
timerId: timerId,
|
|
107
98
|
timerType: 'timeout'
|
|
108
|
-
}
|
|
109
|
-
|
|
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
|
+
}
|
|
110
110
|
};
|
|
111
111
|
var setInterval = function setInterval(func) {
|
|
112
112
|
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
method: 'set',
|
|
121
121
|
params: {
|
|
122
122
|
delay: delay,
|
|
123
|
-
now: performance.now(),
|
|
123
|
+
now: performance.timeOrigin + performance.now(),
|
|
124
124
|
timerId: timerId,
|
|
125
125
|
timerType: 'interval'
|
|
126
126
|
}
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
method: 'set',
|
|
133
133
|
params: {
|
|
134
134
|
delay: delay,
|
|
135
|
-
now: performance.now(),
|
|
135
|
+
now: performance.timeOrigin + performance.now(),
|
|
136
136
|
timerId: timerId,
|
|
137
137
|
timerType: 'interval'
|
|
138
138
|
}
|
|
@@ -148,7 +148,7 @@
|
|
|
148
148
|
method: 'set',
|
|
149
149
|
params: {
|
|
150
150
|
delay: delay,
|
|
151
|
-
now: performance.now(),
|
|
151
|
+
now: performance.timeOrigin + performance.now(),
|
|
152
152
|
timerId: timerId,
|
|
153
153
|
timerType: 'timeout'
|
|
154
154
|
}
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@babel/runtime": "^7.24.5",
|
|
13
13
|
"fast-unique-numbers": "^9.0.5",
|
|
14
14
|
"tslib": "^2.6.2",
|
|
15
|
-
"worker-timers-worker": "^
|
|
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": {
|
|
@@ -40,7 +40,7 @@
|
|
|
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.
|
|
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",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"test": "grunt lint && grunt test"
|
|
81
81
|
},
|
|
82
82
|
"types": "build/es2019/module.d.ts",
|
|
83
|
-
"version": "7.0.
|
|
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
|
|
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
|
|
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
|
|
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,37 +89,33 @@ export const load = (url: string) => {
|
|
|
85
89
|
});
|
|
86
90
|
|
|
87
91
|
const clearInterval = (timerId: number) => {
|
|
88
|
-
if (typeof scheduledIntervalFunctions.get(timerId)
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const id = generateUniqueNumber(unrespondedRequests);
|
|
92
|
+
if (typeof scheduledIntervalFunctions.get(timerId) === 'function') {
|
|
93
|
+
const id = generateUniqueNumber(unrespondedRequests);
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
unrespondedRequests.set(id, { timerId, timerType: 'interval' });
|
|
96
|
+
scheduledIntervalFunctions.set(timerId, id);
|
|
96
97
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
worker.postMessage(<IClearRequest>{
|
|
99
|
+
id,
|
|
100
|
+
method: 'clear',
|
|
101
|
+
params: { timerId, timerType: 'interval' }
|
|
102
|
+
});
|
|
103
|
+
}
|
|
102
104
|
};
|
|
103
105
|
|
|
104
106
|
const clearTimeout = (timerId: number) => {
|
|
105
|
-
if (typeof scheduledTimeoutFunctions.get(timerId)
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const id = generateUniqueNumber(unrespondedRequests);
|
|
107
|
+
if (typeof scheduledTimeoutFunctions.get(timerId) === 'function') {
|
|
108
|
+
const id = generateUniqueNumber(unrespondedRequests);
|
|
110
109
|
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
unrespondedRequests.set(id, { timerId, timerType: 'timeout' });
|
|
111
|
+
scheduledTimeoutFunctions.set(timerId, id);
|
|
113
112
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
113
|
+
worker.postMessage(<IClearRequest>{
|
|
114
|
+
id,
|
|
115
|
+
method: 'clear',
|
|
116
|
+
params: { timerId, timerType: 'timeout' }
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
119
|
};
|
|
120
120
|
|
|
121
121
|
const setInterval = (func: Function, delay = 0) => {
|
|
@@ -131,7 +131,7 @@ export const load = (url: string) => {
|
|
|
131
131
|
method: 'set',
|
|
132
132
|
params: {
|
|
133
133
|
delay,
|
|
134
|
-
now: performance.now(),
|
|
134
|
+
now: performance.timeOrigin + performance.now(),
|
|
135
135
|
timerId,
|
|
136
136
|
timerType: 'interval'
|
|
137
137
|
}
|
|
@@ -144,7 +144,7 @@ export const load = (url: string) => {
|
|
|
144
144
|
method: 'set',
|
|
145
145
|
params: {
|
|
146
146
|
delay,
|
|
147
|
-
now: performance.now(),
|
|
147
|
+
now: performance.timeOrigin + performance.now(),
|
|
148
148
|
timerId,
|
|
149
149
|
timerType: 'interval'
|
|
150
150
|
}
|
|
@@ -163,7 +163,7 @@ export const load = (url: string) => {
|
|
|
163
163
|
method: 'set',
|
|
164
164
|
params: {
|
|
165
165
|
delay,
|
|
166
|
-
now: performance.now(),
|
|
166
|
+
now: performance.timeOrigin + performance.now(),
|
|
167
167
|
timerId,
|
|
168
168
|
timerType: 'timeout'
|
|
169
169
|
}
|