Node.on('input', function(msg, send, done) - what is send for?

The new prototype for receiving a message in a node is, I believe,
node.on('input', function(msg, send, done) {
I can't find any documentation or examples showing what send is for. Can someone elucidate, or point me to the docs please?

send is the send function that's otherwise reachable through this.send(). It is now passed as argument to the input function, I'm looking up the announcement for it as I type.

3 Likes

Don't forget to add a test and a dummy definition if you need to cater to non-v1 uses.

Excellent, thanks for that. I see it is also documented where it should be [1] but not in as full detail as in the blog. I had looked there but missed it.

Where it says "The key difference is that when it's called [send], the runtime will be able to correlate it back to the original msg object that was received", having correlated it back what does it do with that information?

[1] https://nodered.org/docs/creating-nodes/node-js

1 Like

Yes, I had got that bit, thanks.

Today - absolutely nothing.

But in the future it will allow for a better level of metric logging and traceability of messages through flows.

1 Like

OK, thanks. Now, back to the code ...

When I call done(error) then a Catch node picks it up, but I don't get a Complete event. Is that correct? I had expected to get the error then a complete event.

That is correct. It gives a clear separation of flows for success and failure. If you want to trigger something regardless of success or failure, then you can add both nodes and wire them to same next node.

Is it not valid for a node to generate more than one error event then?

1 Like

The node can call node.error as much as it likes.

But it can only call done(error) once for a message when it has finished with it.

But in that case the user can't tell when it has finished, as you don't know whether there is another error coming. Unless the final error is marked as such in some way. That is ok though, I can do that.

A node should make it clear to the user what they can expect.

In most cases, if a node encounters an error that warrants triggering the catch node, then that will end it's processing of the message.

It will only be for specific types of node that it might log multiple errors for a given message - certainly not the norm.

I can't remember if we already add a flag to the error if recorded with done(error). My laptop is asleep and so soon will I be.

1 Like

Certainly, that is arguably the most important point.

I don't think so, I can't see it anyway.

I have some further questions related to this but rather than have the thread head even further off topic I have started a new one with some specific questions.

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