node-red: problem with messages in node.send
If you use node.send from inside a function node, it doesn’t seem to copy the emitted msg properly. In the flow below, you get 1, then 9 10s, rather than the ascending numbers. If you take the delay node out, it works fine, so it’s something about references to objects rather than copies of objects, I suspect.
I can work around it with node.send({payload: i}), but I’d prefer not to.
[{"id":"3935632e.f2d07c","type":"inject","z":"3eed488a.dd7fc","name":"go","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":130,"y":180,"wires":[["2642f404.f305ac"]]},{"id":"2642f404.f305ac","type":"function","z":"3eed488a.dd7fc","name":"cycle","func":"for (var i=1; i<=10; i++)\n{\n msg.payload = i;\n node.send(msg);\n}\n","outputs":1,"noerr":0,"x":310,"y":180,"wires":[["6a81f90e.931578"]]},{"id":"6a81f90e.931578","type":"delay","z":"3eed488a.dd7fc","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"2","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":450,"y":240,"wires":[["fb0663e4.764f08"]]},{"id":"fb0663e4.764f08","type":"debug","z":"3eed488a.dd7fc","name":"","active":true,"console":"false","complete":"false","x":530,"y":300,"wires":[]}]
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (8 by maintainers)
@styltsars96 apologies for the typo -
RED.util.cloneMessage(msg)
(notutils
) is certainly available to the Function node.