@@ -58,9 +58,10 @@ RED.start().then(embeddedStart(RED)).then((result) => {
58
58
// result is whatever RED.start() resolved to
59
59
// RED.node.getFlow() etc are now ready to use
60
60
}).catch ((err ) => {
61
- // theoretically, RED.start() could have rejected, but in practice
62
- // this isn't possible (at present) given the Node-RED code
63
- // so in practice embeddedStart() timed out (see below)
61
+ if (/ ^ timed out/ .test (err .message )) {
62
+ // embeddedStart() timed out
63
+ // the value that RED.start() resolved to is available as err.result
64
+ }
64
65
});
65
66
```
66
67
@@ -74,9 +75,22 @@ embeddedStart.inject(RED);
74
75
// then use RED.start() just as you would normally
75
76
RED .start ().then ((result ) => {
76
77
// RED.node.getFlow() etc are now ready to use
78
+ }).catch ((err ) => {
79
+ // same as above example
77
80
});
78
81
```
79
82
83
+ In either case, the promise returned by the function settles in one of the
84
+ following three ways (the "result value" is optional and should normally be
85
+ the value to which ` RED.start() ` resolves):
86
+ 1 . If the flows API is ready already, the promise resolves immediately with
87
+ the result value passed in.
88
+ 2 . When the ` nodes-started ` event fires, the promise resolves with the result
89
+ value passed in.
90
+ 3 . If the timeout is reached before the ` nodes-started ` event fires, the
91
+ promise rejects with an error. If a result value different from ` undefined `
92
+ is passed in, it is passed through as the ` result ` property of the error.
93
+
80
94
### Usage & API details
81
95
82
96
#### Generate a wait function: ` embeddedStart([RED[, timeout]]) `
0 commit comments