The aim is to give a visual warning in the editor that a flow has stopped flowing using node.status
.
I wrote the code below using setTimeout
but it doesn't seem to work as planned, as it displays "STALE" despite the flow being triggered every 5 seconds.
Am I clearing the previous timeout correctly?
function delay(callback, delay) {
setTimeout(callback, delay);
}
clearTimeout(delay);
node.send({payload: msg.payload})
node.status({ fill: "green", shape: "dot", text: msg.payload + "%" })
delay(function() {
node.status({ fill: "red", shape: "dot", text: "STALE" })
}, 6000)
Example flow
[{"id":"6803e03ca1cb800f","type":"function","z":"c10377724288bc5e","name":"function 5","func":"function delay(callback, delay) {\n setTimeout(callback, delay);\n}\n\nclearTimeout(delay);\n\nnode.send({payload: msg.payload})\nnode.status({ fill: \"green\", shape: \"dot\", text: msg.payload + \"%\" })\ndelay(function() {\n node.status({ fill: \"red\", shape: \"dot\", text: \"STALE\" })\n}, 6000)","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":1460,"wires":[["be5c8a57243cb8bf"]]},{"id":"7a4f70e69da2b462","type":"inject","z":"c10377724288bc5e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$number($floor(1 + $random() * 100))","payloadType":"jsonata","x":510,"y":1460,"wires":[["6803e03ca1cb800f"]]},{"id":"be5c8a57243cb8bf","type":"debug","z":"c10377724288bc5e","name":"debug 43","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":880,"y":1460,"wires":[]}]