# setTimeout usage and 'Deploy' kills it

**URL:** <https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826>\
**Category:** General\
**Created:** [23 February 2024 16:53 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826 "2024-02-23T16:53:41Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Post date:** [23 February 2024 16:53 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826/1 "2024-02-23T16:53:41Z")

</div>

To start a function after a given time '`eTime`' I use a function block `setTimeout(function () {..}, eTime)`. If a 'Deploy' is made within the NR editor, the specified timeout time is canceled. Can this be prevented? If not, what alternative is there?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [23 February 2024 16:58 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826/2 "2024-02-23T16:58:37Z")

</div>

Are you deploying full?  
You can just deploy modified nodes or flows

---

<div class="post-metadata">

**Author:** ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Post date:** [23 February 2024 17:23 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826/3 "2024-02-23T17:23:22Z")

</div>

Good point! But I can't quite get my head around it.  
Suppose the `setTimeout` function is on an editor page ... a 'flow'. If I change an element on this flow, the element gets a blue dot. Regardless of whether I select Deploy for Node or Flow, the blue dot remains, and the 'Deploy' button remains red. This means that the changes are not applied. And the setTimeout is still active.  
But that can't be the solution!  
Only the full Deploy takes the change of the element .. and destroys the setTimeout!

---

<div class="post-metadata">

**Author:** ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Post date:** [23 February 2024 17:28 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826/4 "2024-02-23T17:28:59Z")

</div>

But basically I read from the answer, yes "Deploy" resets a setTimeout function. Right?  
Ask asked before: any alternative for "setTimeout"? Maybe using context/flow/global variables?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [23 February 2024 17:29 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826/5 "2024-02-23T17:29:19Z")

</div>

A full deploy stops all nodes \> deploys all nodes \> restarts all nodes.  
A modified node deploy stops modified nodes \> deploys modified nodes \> restarts modified nodes.

---

<div class="post-metadata">

**Author:** ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Post date:** [23 February 2024 17:33 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826/6 "2024-02-23T17:33:31Z")

</div>

Sorry, can't see that ...  
What could I have done wrong with the "partial deploy"?

---

<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:** [23 February 2024 17:38 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826/7 "2024-02-23T17:38:43Z")

</div>

For anyone else reading this...

**Full Deploy** : Restarts Node RED (in theory)  
**Modified Flows** : Restarts A flow if anything in that flow has changed  
**Modified Nodes** : Restarts only nodes that has been modified

@gNeandr Example: if you have **Modified Flows** set - and changed one node in that flow, and deploy - all nodes will get restarted in that flow

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [23 February 2024 17:50 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826/8 "2024-02-23T17:50:53Z")

</div>

> [@gNeandr](#):
>
> If I change an element on this flow, the element gets a blue dot. Regardless of whether I select Deploy for Node or Flow, the blue dot remains, and the 'Deploy' button remains red. This means that the changes are not applied. And the setTimeout is still active.

If you select Modified Nodes from this dropdown it changes the function of the Deploy button but it does not deploy anything. You still need to click Deploy.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/ca30b6e68a6d8c939f3e7ce387668e4aae2a3233.png)

The Deploy button changes to this to indicate "Changed nodes only" mode.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/392f425247013419854c4ca020d2f1f20177b183.png)

---

<div class="post-metadata">

**Author:** ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Post date:** [23 February 2024 17:52 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826/9 "2024-02-23T17:52:18Z")

</div>

OK, I didn't pay attention to the fact that the Deploy pulldown is "only" a selection menu.  
The Deploy button is changing its function by the pulldown selection and only the use of the button parts makes the Deploy as selected.  
Nice learning 🤪

Any suggestion for the setTimeout NOT to alter ? 🤨

---

<div class="post-metadata">

**Author:** ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Post date:** [23 February 2024 17:54 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826/10 "2024-02-23T17:54:50Z")

</div>

Thanks, I've just noticed.  
Nice to see that help is here 😃

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [23 February 2024 17:56 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826/11 "2024-02-23T17:56:17Z")

</div>

So can you now deploy without resetting the timeout, as long as you didn't move or modify that node?

---

<div class="post-metadata">

**Author:** ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Post date:** [23 February 2024 18:02 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826/12 "2024-02-23T18:02:53Z")

</div>

Will try to do so.  
Just changed some nodes on the flow, but not the function node with the setTimeout.  
atm a setTimeout is "active" for some more 20min, will trace if it's working as expected ... coming back later

---

<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:** [23 February 2024 18:08 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826/13 "2024-02-23T18:08:21Z")

</div>

Just to be grumpy here.... 👴

Consider using a `trigger` or `delay` Node (whatever works best), whilst using context to store anything that might be needed later, at the point of execution.

but granted, it might not be suited for your requirement, just keep it in mind.

---

<div class="post-metadata">

**Author:** ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Post date:** [23 February 2024 18:24 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826/14 "2024-02-23T18:24:36Z")

</div>

OK, first, the function initiated with the setTimeout did what it should do after elapse. So basically all is fine because of the right deploy.

Thanks for the idea of trigger and delay, have to check for that.

---

<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:** [23 May 2024 18:24 UTC](https://discourse.nodered.org/t/settimeout-usage-and-deploy-kills-it/85826/15 "2024-05-23T18:24:42Z")

</div>

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