How does the Complete node work?

I am looking to implement Complete node support for the Node-RED MCU Edition exploration. I've been able to understand many of the built-in nodes well enough to re-implement them, at least in part, for MCU.

I don't really understand the Complete node. I'd like to, so I can try to implement it. The documentation explains:

Trigger a flow when another node completes its handling of a message.

That seems similar to catch and status nodes. But, I'm not sure how a node indicates it is complete. The documentation notes...

Not all nodes will trigger this event - it will depend on whether they have been implemented to support this feature

... but doesn't explain which nodes do trigger a complete. It mentions the "Email sending node" supports complete.

I guess have two questions:

  1. Do any of the core built-in Node-RED nodes support Complete? That would make it straightforward for me to explore the behavior directly by building some test flows.
  2. Other than digging into the full Node-RED sources (which is a big project!), what's the best way to learn how nodes implement support for Complete?

Thank you!

Generally best to give the full name for a node, a generic name like "complete" makes people have to search.

I believe the OP is referring to the built-in complete node.

:rofl: :rofl: I'd forgotten that one existed! Never actually needed to use it.

1 Like

@phoddie if a node uses the done callback` then it supports the complete node.

See here: "JavaScript file : Node-RED" JavaScript file : Node-RED

@Steve-Mcl, that helps, thank you, And leads to some follow-on questions.

The document you refer to is clear. The done callback passes to the event handler must be bound to the msg, so that when done() is called, Node-RED knows which message is done / complete. I can emulate that behavior.

The Writing Functions document in the "Finishing with a message" section shows calling node.done(). A function can have multiple messages pending from what I've seen (the Delay node may receive several messages and wait to pass them along), so it doesn't seem that Node-RED can know which message is done when node.done() is invoked which makes it impossible to trigger the Completion node with message that has the correct message id.

Perhaps it is a implicit requirement that nodes that have multiple messages in-flight use the done callback provided by the event callback. But, can a Function node use the event mechanism (the reference you provided appears to be for implementing nodes using Node.js)?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.