worker-timers-broker 8.0.0 → 8.0.2
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 +61 -0
- package/build/es2019/module.js +2 -2
- package/build/es2019/module.js.map +1 -1
- package/build/es5/bundle.js +2 -2
- package/package.json +12 -12
- package/src/module.ts +2 -2
package/README.md
CHANGED
|
@@ -4,6 +4,67 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/worker-timers-broker)
|
|
6
6
|
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
In most cases using this package via [`worker-timers`](https://github.com/chrisguttandin/worker-timers) is probably the most convenient choice.
|
|
10
|
+
|
|
11
|
+
However `worker-timers-broker` is published as a separate package on npm. It can be installed using the following command:
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
npm install worker-timers-broker
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The package exports two functions.
|
|
18
|
+
|
|
19
|
+
### load()
|
|
20
|
+
|
|
21
|
+
The `load()` function can be used to create a custom instance of `worker-timers` by explicitly specifying the URL which points to the code of the [`worker-timers-worker`](https://github.com/chrisguttandin/worker-timers-worker) package.
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import { load } from 'worker-timers-broker';
|
|
25
|
+
|
|
26
|
+
const { clearInterval, clearTimeout, setInterval, setTimeout } = load('./the/worker-timers-worker/file');
|
|
27
|
+
|
|
28
|
+
const intervalId = setInterval(() => {
|
|
29
|
+
// do something many times
|
|
30
|
+
}, 100);
|
|
31
|
+
|
|
32
|
+
clearInterval(intervalId);
|
|
33
|
+
|
|
34
|
+
const timeoutId = setTimeout(() => {
|
|
35
|
+
// do something once
|
|
36
|
+
}, 100);
|
|
37
|
+
|
|
38
|
+
clearTimeout(timeoutId);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### wrap()
|
|
42
|
+
|
|
43
|
+
The `wrap()` function can be used to wrap a Web Worker instance which already runs the code of the [`worker-timers-worker`](https://github.com/chrisguttandin/worker-timers-worker) package.
|
|
44
|
+
|
|
45
|
+
In a project using [Vite](https://vite.dev) it can for example be used by leveraging [query suffixes](https://vite.dev/guide/features.html#import-with-query-suffixes).
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
import { wrap } from 'worker-timers-broker';
|
|
49
|
+
import createWorkerTimersWorker from 'worker-timers-worker?worker';
|
|
50
|
+
|
|
51
|
+
const { clearInterval, clearTimeout, setInterval, setTimeout } = wrap(createWorkerTimersWorker());
|
|
52
|
+
|
|
53
|
+
const intervalId = setInterval(() => {
|
|
54
|
+
// do something many times
|
|
55
|
+
}, 100);
|
|
56
|
+
|
|
57
|
+
clearInterval(intervalId);
|
|
58
|
+
|
|
59
|
+
const timeoutId = setTimeout(() => {
|
|
60
|
+
// do something once
|
|
61
|
+
}, 100);
|
|
62
|
+
|
|
63
|
+
clearTimeout(timeoutId);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Please note the syntax for other build tools may vary.
|
|
67
|
+
|
|
7
68
|
## Security contact information
|
|
8
69
|
|
|
9
70
|
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
|
package/build/es2019/module.js
CHANGED
|
@@ -42,7 +42,7 @@ export const wrap = createBroker({
|
|
|
42
42
|
timerType: 'interval'
|
|
43
43
|
}).then(() => {
|
|
44
44
|
const state = scheduledIntervalsState.get(timerId);
|
|
45
|
-
if (
|
|
45
|
+
if (state === undefined) {
|
|
46
46
|
throw new Error('The timer is in an undefined state.');
|
|
47
47
|
}
|
|
48
48
|
if (state === symbol) {
|
|
@@ -69,7 +69,7 @@ export const wrap = createBroker({
|
|
|
69
69
|
timerType: 'timeout'
|
|
70
70
|
}).then(() => {
|
|
71
71
|
const state = scheduledTimeoutsState.get(timerId);
|
|
72
|
-
if (
|
|
72
|
+
if (state === undefined) {
|
|
73
73
|
throw new Error('The timer is in an undefined state.');
|
|
74
74
|
}
|
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EAAE;gBACR,KAAK;gBACL,GAAG,EAAE,WAAW,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE;gBAC/C,OAAO;gBACP,SAAS,EAAE,SAAS;aACvB,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;gBACT,MAAM,KAAK,GAAG,sBAAsB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBAElD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;oBACtB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;gBAC3D,CAAC;gBAED,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;oBACnB,kEAAkE;oBAClE,sBAAsB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;oBAEvC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;gBAClB,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,OAAO,OAAO,CAAC;QACnB,CAAC,CAAC;IACN,CAAC;CACJ,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,IAAI,GAA8B,CAAC,GAAW,EAAE,EAAE;IAC3D,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;IAE/B,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;AACxB,CAAC,CAAC"}
|
package/build/es5/bundle.js
CHANGED
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
timerType: 'interval'
|
|
55
55
|
}).then(function () {
|
|
56
56
|
var state = scheduledIntervalsState.get(timerId);
|
|
57
|
-
if (
|
|
57
|
+
if (state === undefined) {
|
|
58
58
|
throw new Error('The timer is in an undefined state.');
|
|
59
59
|
}
|
|
60
60
|
if (state === symbol) {
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
timerType: 'timeout'
|
|
88
88
|
}).then(function () {
|
|
89
89
|
var state = scheduledTimeoutsState.get(timerId);
|
|
90
|
-
if (
|
|
90
|
+
if (state === undefined) {
|
|
91
91
|
throw new Error('The timer is in an undefined state.');
|
|
92
92
|
}
|
|
93
93
|
if (state === symbol) {
|
package/package.json
CHANGED
|
@@ -9,18 +9,18 @@
|
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@babel/runtime": "^7.26.
|
|
13
|
-
"broker-factory": "^3.1.
|
|
14
|
-
"fast-unique-numbers": "^9.0.
|
|
12
|
+
"@babel/runtime": "^7.26.9",
|
|
13
|
+
"broker-factory": "^3.1.1",
|
|
14
|
+
"fast-unique-numbers": "^9.0.16",
|
|
15
15
|
"tslib": "^2.8.1",
|
|
16
|
-
"worker-timers-worker": "^9.0.
|
|
16
|
+
"worker-timers-worker": "^9.0.2"
|
|
17
17
|
},
|
|
18
18
|
"description": "The broker which is used by the worker-timers package.",
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@babel/core": "^7.26.
|
|
20
|
+
"@babel/core": "^7.26.9",
|
|
21
21
|
"@babel/plugin-external-helpers": "^7.25.9",
|
|
22
|
-
"@babel/plugin-transform-runtime": "^7.26.
|
|
23
|
-
"@babel/preset-env": "^7.26.
|
|
22
|
+
"@babel/plugin-transform-runtime": "^7.26.9",
|
|
23
|
+
"@babel/preset-env": "^7.26.9",
|
|
24
24
|
"@commitlint/cli": "^19.7.1",
|
|
25
25
|
"@commitlint/config-angular": "^19.7.1",
|
|
26
26
|
"@rollup/plugin-babel": "^6.0.4",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"commitizen": "^4.3.1",
|
|
29
29
|
"cz-conventional-changelog": "^3.3.0",
|
|
30
30
|
"eslint": "^8.57.0",
|
|
31
|
-
"eslint-config-holy-grail": "^60.0.
|
|
31
|
+
"eslint-config-holy-grail": "^60.0.19",
|
|
32
32
|
"grunt": "^1.6.1",
|
|
33
33
|
"grunt-cli": "^1.5.0",
|
|
34
34
|
"grunt-sh": "^0.2.1",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"lint-staged": "^15.4.3",
|
|
45
45
|
"load-grunt-config": "^4.0.1",
|
|
46
46
|
"mocha": "^10.8.2",
|
|
47
|
-
"prettier": "^3.5.
|
|
47
|
+
"prettier": "^3.5.2",
|
|
48
48
|
"rimraf": "^6.0.1",
|
|
49
|
-
"rollup": "^4.34.
|
|
49
|
+
"rollup": "^4.34.8",
|
|
50
50
|
"sinon": "^17.0.2",
|
|
51
51
|
"sinon-chai": "^3.7.0",
|
|
52
52
|
"ts-loader": "^9.5.2",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"tslint": "^6.1.3",
|
|
55
55
|
"tslint-config-holy-grail": "^56.0.6",
|
|
56
56
|
"typescript": "^5.7.3",
|
|
57
|
-
"webpack": "^5.
|
|
57
|
+
"webpack": "^5.98.0"
|
|
58
58
|
},
|
|
59
59
|
"files": [
|
|
60
60
|
"build/es2019/",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"test": "grunt lint && grunt test"
|
|
82
82
|
},
|
|
83
83
|
"types": "build/es2019/module.d.ts",
|
|
84
|
-
"version": "8.0.
|
|
84
|
+
"version": "8.0.2"
|
|
85
85
|
}
|
package/src/module.ts
CHANGED
|
@@ -54,7 +54,7 @@ export const wrap: TWorkerTimersBrokerWrapper = createBroker<IWorkerTimersBroker
|
|
|
54
54
|
}).then(() => {
|
|
55
55
|
const state = scheduledIntervalsState.get(timerId);
|
|
56
56
|
|
|
57
|
-
if (
|
|
57
|
+
if (state === undefined) {
|
|
58
58
|
throw new Error('The timer is in an undefined state.');
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -88,7 +88,7 @@ export const wrap: TWorkerTimersBrokerWrapper = createBroker<IWorkerTimersBroker
|
|
|
88
88
|
}).then(() => {
|
|
89
89
|
const state = scheduledTimeoutsState.get(timerId);
|
|
90
90
|
|
|
91
|
-
if (
|
|
91
|
+
if (state === undefined) {
|
|
92
92
|
throw new Error('The timer is in an undefined state.');
|
|
93
93
|
}
|
|
94
94
|
|