Node-RED version 2.2, Node version 16.14.0:
I was working on a semi-complex flow containing a Trigger Node. The flow was not producing the desired result. I narrowed it down to the Trigger node by creating a simple test flow (see attached JSON export below). My trigger node is setup to send the existing msg object, wait for a specified time, extend the delay if a new message arrives, and then send the latest msg object when the timer expires. The problem is, I get the same result no matter which option I select for "then send" (original or latest). That is, it returns the original message when "then send" is set to "latest".
Playing around with my simple test flow I determined it works as expected but ONLY when the "Handling" option is set to "all messages". My actual flow is using the "each" message.option. I was expecting the node to give me the latest message on a per topic basis because everything else (e.g. the actual timer itself) appears to work on a per topic basis when "Handling" is set to "each". My question: is this by design? If so, i can work around it...no big deal. However, I decided to ask the question just in case this is a bug. If this is intended behavior it would be nice if the help text in the sidebar mentions that. Thanks in advance!
Simple Test Flow:
[
{
"id": "4a3c07bce144963c",
"type": "debug",
"z": "d33fb4473770860c",
"name": "Debug Latest",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 790,
"y": 1120,
"wires": []
},
{
"id": "ddcabcc54e0ee621",
"type": "trigger",
"z": "d33fb4473770860c",
"name": "Latest",
"op1": "",
"op2": "",
"op1type": "pay",
"op2type": "payl",
"duration": "15",
"extend": true,
"overrideDelay": false,
"units": "s",
"reset": "",
"bytopic": "all",
"topic": "topic",
"outputs": 1,
"x": 590,
"y": 1120,
"wires": [
[
"4a3c07bce144963c"
]
]
},
{
"id": "bc006f989eb24044",
"type": "function",
"z": "d33fb4473770860c",
"name": "",
"func": "if (msg.resetCount === true) {\n context.set('count', 0);\n return null;\n}\n\nlet count = context.get('count') || 0;\ncount = count + 1;\ncontext.set('count', count)\nmsg1 = {topic: msg.topic};\nmsg1.payload = count;\n\nreturn msg1;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 380,
"y": 1180,
"wires": [
[
"ddcabcc54e0ee621",
"5df271dd70f0740e"
]
]
},
{
"id": "40d6d2cd7bb142fd",
"type": "inject",
"z": "d33fb4473770860c",
"name": "",
"props": [
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "TEST",
"x": 150,
"y": 1180,
"wires": [
[
"bc006f989eb24044"
]
]
},
{
"id": "5df271dd70f0740e",
"type": "trigger",
"z": "d33fb4473770860c",
"name": "Original",
"op1": "",
"op2": "",
"op1type": "pay",
"op2type": "pay",
"duration": "30",
"extend": true,
"overrideDelay": false,
"units": "s",
"reset": "",
"bytopic": "topic",
"topic": "topic",
"outputs": 1,
"x": 600,
"y": 1240,
"wires": [
[
"b71c2c3b0d2844bf"
]
]
},
{
"id": "3f112364a5eeed2b",
"type": "inject",
"z": "d33fb4473770860c",
"name": "Reset Counter",
"props": [
{
"p": "resetCount",
"v": "true",
"vt": "bool"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 180,
"y": 1100,
"wires": [
[
"bc006f989eb24044"
]
]
},
{
"id": "b71c2c3b0d2844bf",
"type": "debug",
"z": "d33fb4473770860c",
"name": "Debug Original",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 800,
"y": 1240,
"wires": []
}
]