worker-lib 2.0.7 → 2.0.9
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/LICENSE +1 -1
- package/README.md +32 -0
- package/package.json +4 -4
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# worker-lib
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/worker-lib)
|
|
4
|
+
[](https://www.npmjs.com/package/worker-lib)
|
|
5
|
+
[](https://www.npmjs.com/package/worker-lib)
|
|
6
|
+
[](https://deepwiki.com/SoraKumo001/worker-lib)
|
|
7
|
+
|
|
3
8
|
## Overview
|
|
4
9
|
|
|
5
10
|
Library for easy use of web-worker and worker_threads.
|
|
@@ -151,6 +156,33 @@ const map = initWorker({ add, add2, sub, mul, error });
|
|
|
151
156
|
export type WorkerTest = typeof map;
|
|
152
157
|
```
|
|
153
158
|
|
|
159
|
+
### Callback
|
|
160
|
+
|
|
161
|
+
`worker-lib` supports passing callback functions to workers.
|
|
162
|
+
|
|
163
|
+
- worker.ts
|
|
164
|
+
```ts
|
|
165
|
+
import { initWorker } from "worker-lib";
|
|
166
|
+
|
|
167
|
+
const progressTask = async (onProgress: (percent: number) => void) => {
|
|
168
|
+
onProgress(10);
|
|
169
|
+
// ... heavy task ...
|
|
170
|
+
onProgress(50);
|
|
171
|
+
// ... heavy task ...
|
|
172
|
+
onProgress(100);
|
|
173
|
+
return "Done";
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
initWorker({ progressTask });
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
- main.ts
|
|
180
|
+
```ts
|
|
181
|
+
const result = await execute("progressTask", (percent) => {
|
|
182
|
+
console.log(`Progress: ${percent}%`);
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
154
186
|
- src/app/page.tsx
|
|
155
187
|
|
|
156
188
|
```tsx
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "worker-lib",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"types": "./dist/cjs/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"build": "tsc && tsc --project ./tsconfig.esm.json && cpy esm dist"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@types/node": "
|
|
52
|
-
"cpy-cli": "
|
|
53
|
-
"typescript": "^5.
|
|
51
|
+
"@types/node": "25.2.3",
|
|
52
|
+
"cpy-cli": "7.0.0",
|
|
53
|
+
"typescript": "^5.9.3"
|
|
54
54
|
},
|
|
55
55
|
"description": "Library for easy use of web-worker",
|
|
56
56
|
"repository": {
|