# Using node.status to indicate that a flow has stopped

**URL:** <https://discourse.nodered.org/t/using-node-status-to-indicate-that-a-flow-has-stopped/84603>\
**Category:** General\
**Created:** [16 January 2024 12:48 UTC](https://discourse.nodered.org/t/using-node-status-to-indicate-that-a-flow-has-stopped/84603 "2024-01-16T12:48:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [16 January 2024 12:48 UTC](https://discourse.nodered.org/t/using-node-status-to-indicate-that-a-flow-has-stopped/84603/1 "2024-01-16T12:48:30Z")

</div>

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?

```auto
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

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [16 January 2024 12:59 UTC](https://discourse.nodered.org/t/using-node-status-to-indicate-that-a-flow-has-stopped/84603/2 "2024-01-16T12:59:13Z")

</div>

Hi @Paul-Reed

I _think_ its just a context thing.

try this..  
when i tested , it went stale only after disconnecting the wire and deploying

`setTimeout` returns and object that you can pass to `clearTimeout`  
but to cancel it, it must be stored in context, given the nature of `function` nodes

```auto
let _timer = context.get("timer")
function timeout(){
    node.status({ fill: "red", shape: "dot", text: "STALE" })
}
if(_timer){
    clearTimeout(_timer);
}

node.send({payload: msg.payload})
node.status({ fill: "green", shape: "dot", text: msg.payload + "%" })

_timer = setTimeout(timeout,6000);
context.set("timer",_timer)

```

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [16 January 2024 19:26 UTC](https://discourse.nodered.org/t/using-node-status-to-indicate-that-a-flow-has-stopped/84603/3 "2024-01-16T19:26:50Z")

</div>

> [@marcus-j-davies](#):
>
> I _think_ its just a context thing.

Thanks Marcus, your code works great!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 January 2024 19:27 UTC](https://discourse.nodered.org/t/using-node-status-to-indicate-that-a-flow-has-stopped/84603/4 "2024-01-30T19:27:09Z")

</div>

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