Skip to content

Commit 79c7c03

Browse files
committed
Various documentation fixes and polishing
Should fix #4, at least for now.
1 parent 728abf2 commit 79c7c03

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

README.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@ in obscure internal Node-RED errors (typically, `TypeError` being thrown)
1313
if one calls certain runtime or admin API method too early. This module
1414
allows waiting deterministically for the runtime API for flows to be ready.
1515

16+
## Use cases
17+
1618
If your primary need is to interact programmatically with the flows API of
1719
an [embedded Node-RED] instance once it starts up, then this module is for
18-
you. One example use case likely faced by many developers (such as myself)
20+
you.
21+
22+
One use case likely faced by many developers (such as myself)
1923
of nodes for Node-RED is running automatic testing for their node(s). Ideally
2024
such testing can include testing discovery, loading, and running of nodes
21-
by a live embedded Node-RED instance.
22-
23-
_(In the wild, those who run such tests, including Node-RED itself, seem
24-
to be using mocks of Node-RED. Not only do the mocks take a lot of code to
25-
create, they are also at risk of diverging from what a live Node-RED instance
26-
does. Hence, personally I would rather test manually than use a mock, or
27-
waste my time on creating one.)_
25+
by a live embedded Node-RED instance. Usually, one of the first steps in
26+
getting a node to "run" (i.e., Node-RED invoking the constructor for the
27+
node type) is to add it to a flow, whether one that exists or one that you
28+
create from scratch programmatically.
2829

2930
## Installation
3031

@@ -56,7 +57,7 @@ promise chain from RED.start():
5657
var embeddedStart = require('node-red-embedded-start');
5758
RED.start().then(embeddedStart(RED)).then((result) => {
5859
// result is whatever RED.start() resolved to
59-
// RED.node.getFlow() etc are now ready to use
60+
// RED.node.getFlows() etc are now ready to use
6061
}).catch((err) => {
6162
if (/^timed out/.test(err.message)) {
6263
// embeddedStart() timed out
@@ -103,6 +104,14 @@ RED.start().then(waitFunc).then(() => {
103104
});
104105
```
105106

107+
Usually, because the wait function will only be used once, one will write
108+
the call directly into the promise chain:
109+
```js
110+
RED.start().then(embeddedStart(RED, 5000)).then((result) => {
111+
// do whatever
112+
});
113+
```
114+
106115
* `RED` is the embedded Node-RED instance.
107116
* `timeout` is the time in milliseconds after which waiting for the
108117
`nodes-started` event should time out. Optional, default is 30 seconds.
@@ -154,11 +163,12 @@ some time and hope for the best. Although a couple of seconds will often
154163
suffice, the time needed will depend on processor speed, storage speed,
155164
number of flows, number of nodes in those flows, and various other factors.
156165
A wait-and-hope-for-the-best solution seems therefore unsatisfactory, and
157-
still requires code to implement.
166+
nevertheless also requires code to implement.
158167

159168
This issue has been brought to the attention of the Node-RED developers
160-
[Node-RED issue #1168], but they responded that the behaviour is intentional
161-
and will thus not be fixed.
169+
(see Node-RED issues [#1168] and [#902]), but they responded that the behaviour
170+
is intentional and will thus not be fixed until the behavior of an embedded
171+
application is fully defined and implemented.
162172

163173
This module allows waiting instead for a certain event (`nodes-started`) to
164174
fire. The event fires at a point in time during the Node-RED startup when
@@ -175,13 +185,14 @@ the code driving the flow API is initialized and thus ready for interaction.
175185
the flow API being ready does _not_ (and _should_ not) mean that any other
176186
components have fully completed their initialization as well. For example,
177187
the constructors of nodes may themselves have launched initialization tasks
178-
asynchronously, and there is no way of knowing which in which stage
179-
these are. See [Node-RED issue 698] for discussion.
188+
asynchronously, and there is no way of knowing in which stage
189+
these are. See Node-RED issue [#698] for discussion.
180190

181191
## License
182192

183-
MIT
193+
Available under the [MIT License](LICENSE).
184194

185-
[Node-RED issue #1168]: https://github.com/node-red/node-red/issues/1168
186-
[Node-RED issue 698]: https://github.com/node-red/node-red/issues/698
195+
[#1168]: https://github.com/node-red/node-red/issues/1168
196+
[#902]: https://github.com/node-red/node-red/issues/902
197+
[#698]: https://github.com/node-red/node-red/issues/698
187198
[embedded Node-RED]: http://nodered.org/docs/embedding

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
},
1515
"keywords": [
1616
"node-red",
17-
"embedded"
17+
"embedded",
18+
"iot"
1819
],
1920
"author": "Hilmar Lapp <hilmar@lappland.io>",
2021
"license": "MIT",

0 commit comments

Comments
 (0)