worker-lib 2.0.8 → 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.
Files changed (2) hide show
  1. package/README.md +27 -0
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -156,6 +156,33 @@ const map = initWorker({ add, add2, sub, mul, error });
156
156
  export type WorkerTest = typeof map;
157
157
  ```
158
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
+
159
186
  - src/app/page.tsx
160
187
 
161
188
  ```tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "worker-lib",
3
- "version": "2.0.8",
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": "24.0.3",
52
- "cpy-cli": "5.0.0",
53
- "typescript": "^5.8.3"
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": {