@nrutils/node-red-utils 0.1.0 → 0.2.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/CHANGELOG.md +5 -0
- package/README.md +6 -0
- package/node-red-popup/NodeRedPopupFrontend.js +190 -96
- package/node-red-popup/README.md +6 -3
- package/node-red-worker/NodeRedWorker.js +443 -438
- package/node-red-worker/NodeRedWorkerRuntime.js +658 -650
- package/node-red-worker/README.md +9 -1
- package/package.json +2 -2
|
@@ -179,7 +179,13 @@ The worker is not restarted. Its wires to other workers are closed. A Full deplo
|
|
|
179
179
|
|
|
180
180
|
When a redeploy or a delete closes the node, the pending requests reject with `worker request ended: the node closed`.
|
|
181
181
|
|
|
182
|
-
A throw inside a `subscribe` handler in the worker is different: the runtime catches it and
|
|
182
|
+
A throw inside a `subscribe` handler in the worker is different: the runtime catches it and calls `worker.handlerError(error, type, data)`, and the worker keeps running. The other handlers for the same message still run. The default `handlerError` sends the error to the node, which logs `worker message handler for '<type>' failed: <message>` with `node.error`, the same text as for a main-thread handler. A Catch node gets it. A worker file can replace it, for example to add its own text. `data` is the data of the message that the handler got.
|
|
183
|
+
|
|
184
|
+
```js
|
|
185
|
+
worker.handlerError = (error, type, data) => worker.parentPorts.publish('problem', `${type}: ${error.message}`);
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
A throw inside a `handle` handler goes back to the caller of `request()`.
|
|
183
189
|
|
|
184
190
|
`publish()` and `request()` use the structured clone algorithm. Data that cannot be cloned, such as a function or an object that contains a function, makes `publish()` throw a `DataCloneError` at once, and makes `request()` reject with it. An answer from `handle()` that cannot be cloned rejects the request.
|
|
185
191
|
|
|
@@ -226,6 +232,8 @@ Your worker file exports `function (worker, data)` (see [Worker file](#worker-fi
|
|
|
226
232
|
|
|
227
233
|
`worker.handle(type, handler)`: answer the main thread's `request(type, ...)`. `handler(data, transferList)` returns the answer or a Promise for it. For `transferList`, see [Big results](#big-results). One handler for each type; a second `handle()` for the same type throws.
|
|
228
234
|
|
|
235
|
+
`worker.handlerError(error, type, data)`: the runtime calls it when a `subscribe` handler throws or returns a promise that rejects. `data` is the data of the message. Set your own function to replace the default. See [Errors](#errors).
|
|
236
|
+
|
|
229
237
|
`worker` has three port groups:
|
|
230
238
|
|
|
231
239
|
- `worker.parentPorts`: to and from the main-thread node.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nrutils/node-red-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Mixin toolkit for authors of Node-RED custom nodes: editor messaging, worker threads, popups, singletons, resource serving, pub/sub and optional GPU compute.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"node-addon-api": "^8.7.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"node-red": "^
|
|
66
|
+
"node-red": "^5.0.9"
|
|
67
67
|
},
|
|
68
68
|
"publishConfig": {
|
|
69
69
|
"access": "public"
|