I'm trying to run asynchronous code within nodes that run in parallel, where the following is an example of a flow which does this. The important parts are the Async 1 and Async 2 nodes.
These Async nodes are of the same type, and contain the following code which will run when they receive input. For context, the purpose of shell.execute()
here is to run some Python code in a child process, the async function will wait for it to complete execution, and once it does the async function will continue.
However, this is not working as expected. The following demonstrates the order in which the code blocks are executing.
As shown, execution is flowing like so:
-
shell.execute(runner)
executes for the Async 1 node. -
shell.execute(runner)
executes for the Async 2 node. -
shell.execute(result)
executes for the Async 1 node. -
shell.execute(result)
executes for the Async 2 node. - The Async 1 node ends.
- The Async 2 node ends.
The order of execution is getting jumbled up; what I want is to execute the entire function before moving onto the next node. So under correct circumstances, execution would go like so:
-
shell.execute(runner)
executes for the Async 1 node. -
shell.execute(result)
executes for the Async 1 node. - The Async 1 node ends.
-
shell.execute(runner)
executes for the Async 2 node. -
shell.execute(result)
executes for the Async 2 node. - The Async 2 node ends.
I suspect the reason for this may be related to how Node-RED runs flows in parallel, as described here and shown in this image.
So my question is, how can I modify my code so that it will finish executing Async 1 before beginning to execute Async 2?