worker-timers 7.1.8 → 8.0.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/README.md +2 -14
- package/build/es2019/worker/worker.d.ts +1 -1
- package/build/es2019/worker/worker.d.ts.map +1 -1
- package/build/es2019/worker/worker.js +1 -1
- package/build/es2019/worker/worker.js.map +1 -1
- package/build/es5/bundle.js +1 -1
- package/package.json +7 -7
- package/src/worker/worker.ts +1 -1
package/README.md
CHANGED
|
@@ -42,21 +42,9 @@ var timeoutId = setTimeout(() => {
|
|
|
42
42
|
clearTimeout(timeoutId);
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
## Error Handling
|
|
46
|
-
|
|
47
|
-
The native WindowTimers are very forgiving. Calling `clearInterval()` or `clearTimeout()` without a value or with an id which doesn't exist will get ignored. In contrast to that `worker-timers` will throw an error when doing so.
|
|
48
|
-
|
|
49
|
-
```js
|
|
50
|
-
// This will return undefined.
|
|
51
|
-
window.clearTimeout('not-a-timeout-id');
|
|
52
|
-
|
|
53
|
-
// This will throw an error.
|
|
54
|
-
clearTimeout('not-a-timeout-id');
|
|
55
|
-
```
|
|
56
|
-
|
|
57
45
|
## Differentiation between Intervals and Timeouts
|
|
58
46
|
|
|
59
|
-
|
|
47
|
+
The native WindowTimers only maintain a single list of timers. But `worker-timers` maintains two separate lists to store the ids of intervals and timeouts internally. WindowTimers allows intervals to be cancelled by calling `clearTimeout()` and the other way round because it stores all timers in a single list. This is not possible with `worker-timers`.
|
|
60
48
|
|
|
61
49
|
```js
|
|
62
50
|
const periodicWork = () => {};
|
|
@@ -65,7 +53,7 @@ const periodicWork = () => {};
|
|
|
65
53
|
const windowId = window.setInterval(periodicWork, 100);
|
|
66
54
|
window.clearTimeout(windowId);
|
|
67
55
|
|
|
68
|
-
// This will
|
|
56
|
+
// This will not cancel the interval. It may cancel a timeout.
|
|
69
57
|
const workerId = setInterval(periodicWork, 100);
|
|
70
58
|
clearTimeout(workerId);
|
|
71
59
|
```
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const worker = "(()=>{\"use strict\";const e=new Map,t=new Map,r=(e
|
|
1
|
+
export declare const worker = "(()=>{\"use strict\";const e=new Map,t=new Map,r=t=>{const r=e.get(t);return void 0!==r&&(clearTimeout(r),e.delete(t),!0)},s=e=>{const r=t.get(e);return void 0!==r&&(clearTimeout(r),t.delete(e),!0)},o=(e,t)=>{const r=performance.now(),s=e+t-r-performance.timeOrigin;return{expected:r+s,remainingDelay:s}},i=(e,t,r,s)=>{const o=r-performance.now();o>0?e.set(t,setTimeout(i,o,e,t,r,s)):(e.delete(t),postMessage({id:null,method:\"call\",params:{timerId:t,timerType:s}}))};addEventListener(\"message\",(n=>{let{data:a}=n;try{if(\"clear\"===a.method){const{id:e,params:{timerId:t,timerType:o}}=a;if(\"interval\"===o)postMessage({id:e,result:r(t)});else{if(\"timeout\"!==o)throw new Error('The given type \"'.concat(o,'\" is not supported'));postMessage({id:e,result:s(t)})}}else{if(\"set\"!==a.method)throw new Error('The given method \"'.concat(a.method,'\" is not supported'));{const{params:{delay:r,now:s,timerId:n,timerType:m}}=a;if(\"interval\"===m)((t,r,s)=>{const{expected:n,remainingDelay:a}=o(t,s);e.set(r,setTimeout(i,a,e,r,n,\"interval\"))})(r,n,s);else{if(\"timeout\"!==m)throw new Error('The given type \"'.concat(m,'\" is not supported'));((e,r,s)=>{const{expected:n,remainingDelay:a}=o(e,s);t.set(r,setTimeout(i,a,t,r,n,\"timeout\"))})(r,n,s)}}}}catch(e){postMessage({error:{message:e.message},id:a.id,result:null})}}))})();";
|
|
2
2
|
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/worker/worker.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/worker/worker.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,MAAM,2zCAA+xC,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// This is the minified and stringified code of the worker-timers-worker package.
|
|
2
|
-
export const worker = `(()=>{"use strict";const e=new Map,t=new Map,r=(e
|
|
2
|
+
export const worker = `(()=>{"use strict";const e=new Map,t=new Map,r=t=>{const r=e.get(t);return void 0!==r&&(clearTimeout(r),e.delete(t),!0)},s=e=>{const r=t.get(e);return void 0!==r&&(clearTimeout(r),t.delete(e),!0)},o=(e,t)=>{const r=performance.now(),s=e+t-r-performance.timeOrigin;return{expected:r+s,remainingDelay:s}},i=(e,t,r,s)=>{const o=r-performance.now();o>0?e.set(t,setTimeout(i,o,e,t,r,s)):(e.delete(t),postMessage({id:null,method:"call",params:{timerId:t,timerType:s}}))};addEventListener("message",(n=>{let{data:a}=n;try{if("clear"===a.method){const{id:e,params:{timerId:t,timerType:o}}=a;if("interval"===o)postMessage({id:e,result:r(t)});else{if("timeout"!==o)throw new Error('The given type "'.concat(o,'" is not supported'));postMessage({id:e,result:s(t)})}}else{if("set"!==a.method)throw new Error('The given method "'.concat(a.method,'" is not supported'));{const{params:{delay:r,now:s,timerId:n,timerType:m}}=a;if("interval"===m)((t,r,s)=>{const{expected:n,remainingDelay:a}=o(t,s);e.set(r,setTimeout(i,a,e,r,n,"interval"))})(r,n,s);else{if("timeout"!==m)throw new Error('The given type "'.concat(m,'" is not supported'));((e,r,s)=>{const{expected:n,remainingDelay:a}=o(e,s);t.set(r,setTimeout(i,a,t,r,n,"timeout"))})(r,n,s)}}}}catch(e){postMessage({error:{message:e.message},id:a.id,result:null})}}))})();`; // tslint:disable-line:max-line-length
|
|
3
3
|
//# sourceMappingURL=worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/worker/worker.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,MAAM,CAAC,MAAM,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/worker/worker.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,MAAM,CAAC,MAAM,MAAM,GAAG,4xCAA4xC,CAAC,CAAC,sCAAsC"}
|
package/build/es5/bundle.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
// This is the minified and stringified code of the worker-timers-worker package.
|
|
27
|
-
var worker = "(()=>{var e={472:(e,t,r)=>{var o,
|
|
27
|
+
var worker = "(()=>{var e={472:(e,t,r)=>{var o,n;void 0===(n=\"function\"==typeof(o=function(){\"use strict\";var e=new Map,t=new Map,r=function(t){var r=e.get(t);return void 0!==r&&(clearTimeout(r),e.delete(t),!0)},o=function(e){var r=t.get(e);return void 0!==r&&(clearTimeout(r),t.delete(e),!0)},n=function(e,t){var r=performance.now(),o=e+t-r-performance.timeOrigin;return{expected:r+o,remainingDelay:o}},i=function e(t,r,o,n){var i=o-performance.now();i>0?t.set(r,setTimeout(e,i,t,r,o,n)):(t.delete(r),postMessage({id:null,method:\"call\",params:{timerId:r,timerType:n}}))},a=function(t,r,o){var a=n(t,o),s=a.expected,u=a.remainingDelay;e.set(r,setTimeout(i,u,e,r,s,\"interval\"))},s=function(e,r,o){var a=n(e,o),s=a.expected,u=a.remainingDelay;t.set(r,setTimeout(i,u,t,r,s,\"timeout\"))};addEventListener(\"message\",(function(e){var t=e.data;try{if(\"clear\"===t.method){var n=t.id,i=t.params,u=i.timerId,d=i.timerType;if(\"interval\"===d)postMessage({id:n,result:r(u)});else{if(\"timeout\"!==d)throw new Error('The given type \"'.concat(d,'\" is not supported'));postMessage({id:n,result:o(u)})}}else{if(\"set\"!==t.method)throw new Error('The given method \"'.concat(t.method,'\" is not supported'));var p=t.params,c=p.delay,m=p.now,l=p.timerId,v=p.timerType;if(\"interval\"===v)a(c,l,m);else{if(\"timeout\"!==v)throw new Error('The given type \"'.concat(v,'\" is not supported'));s(c,l,m)}}}catch(e){postMessage({error:{message:e.message},id:t.id,result:null})}}))})?o.call(t,r,t,e):o)||(e.exports=n)}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var i=t[o]={exports:{}};return e[o](i,i.exports,r),i.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{\"use strict\";r(472)})()})();"; // tslint:disable-line:max-line-length
|
|
28
28
|
|
|
29
29
|
var loadOrReturnBroker = createLoadOrReturnBroker(workerTimersBroker.load, worker);
|
|
30
30
|
var clearInterval = function clearInterval(timerId) {
|
package/package.json
CHANGED
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.24.5",
|
|
19
19
|
"tslib": "^2.6.2",
|
|
20
|
-
"worker-timers-broker": "^
|
|
21
|
-
"worker-timers-worker": "^
|
|
20
|
+
"worker-timers-broker": "^7.0.1",
|
|
21
|
+
"worker-timers-worker": "^8.0.0"
|
|
22
22
|
},
|
|
23
23
|
"description": "A replacement for setInterval() and setTimeout() which works in unfocused windows.",
|
|
24
24
|
"devDependencies": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"commitizen": "^4.3.0",
|
|
38
38
|
"cz-conventional-changelog": "^3.3.0",
|
|
39
39
|
"eslint": "^8.57.0",
|
|
40
|
-
"eslint-config-holy-grail": "^59.0.
|
|
40
|
+
"eslint-config-holy-grail": "^59.0.10",
|
|
41
41
|
"grunt": "^1.6.1",
|
|
42
42
|
"grunt-cli": "^1.4.3",
|
|
43
43
|
"grunt-sh": "^0.2.1",
|
|
@@ -50,14 +50,14 @@
|
|
|
50
50
|
"karma-sinon-chai": "^2.0.2",
|
|
51
51
|
"karma-webkit-launcher": "^2.4.0",
|
|
52
52
|
"karma-webpack": "^5.0.1",
|
|
53
|
-
"lint-staged": "^15.2.
|
|
53
|
+
"lint-staged": "^15.2.4",
|
|
54
54
|
"load-grunt-config": "^4.0.1",
|
|
55
55
|
"memfs": "^4.9.2",
|
|
56
56
|
"mocha": "^10.4.0",
|
|
57
57
|
"prettier": "^3.2.5",
|
|
58
|
-
"rimraf": "^5.0.
|
|
58
|
+
"rimraf": "^5.0.7",
|
|
59
59
|
"rollup": "^4.17.2",
|
|
60
|
-
"sinon": "^17.0.
|
|
60
|
+
"sinon": "^17.0.2",
|
|
61
61
|
"sinon-chai": "^3.7.0",
|
|
62
62
|
"terser-webpack-plugin": "^5.3.10",
|
|
63
63
|
"ts-loader": "^9.5.1",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"test": "grunt lint && grunt test"
|
|
103
103
|
},
|
|
104
104
|
"types": "build/es2019/module.d.ts",
|
|
105
|
-
"version": "
|
|
105
|
+
"version": "8.0.0"
|
|
106
106
|
}
|
package/src/worker/worker.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This is the minified and stringified code of the worker-timers-worker package.
|
|
2
|
-
export const worker = `(()=>{"use strict";const e=new Map,t=new Map,r=(e
|
|
2
|
+
export const worker = `(()=>{"use strict";const e=new Map,t=new Map,r=t=>{const r=e.get(t);return void 0!==r&&(clearTimeout(r),e.delete(t),!0)},s=e=>{const r=t.get(e);return void 0!==r&&(clearTimeout(r),t.delete(e),!0)},o=(e,t)=>{const r=performance.now(),s=e+t-r-performance.timeOrigin;return{expected:r+s,remainingDelay:s}},i=(e,t,r,s)=>{const o=r-performance.now();o>0?e.set(t,setTimeout(i,o,e,t,r,s)):(e.delete(t),postMessage({id:null,method:"call",params:{timerId:t,timerType:s}}))};addEventListener("message",(n=>{let{data:a}=n;try{if("clear"===a.method){const{id:e,params:{timerId:t,timerType:o}}=a;if("interval"===o)postMessage({id:e,result:r(t)});else{if("timeout"!==o)throw new Error('The given type "'.concat(o,'" is not supported'));postMessage({id:e,result:s(t)})}}else{if("set"!==a.method)throw new Error('The given method "'.concat(a.method,'" is not supported'));{const{params:{delay:r,now:s,timerId:n,timerType:m}}=a;if("interval"===m)((t,r,s)=>{const{expected:n,remainingDelay:a}=o(t,s);e.set(r,setTimeout(i,a,e,r,n,"interval"))})(r,n,s);else{if("timeout"!==m)throw new Error('The given type "'.concat(m,'" is not supported'));((e,r,s)=>{const{expected:n,remainingDelay:a}=o(e,s);t.set(r,setTimeout(i,a,t,r,n,"timeout"))})(r,n,s)}}}}catch(e){postMessage({error:{message:e.message},id:a.id,result:null})}}))})();`; // tslint:disable-line:max-line-length
|