# Time taken to set a global variable?

**URL:** <https://discourse.nodered.org/t/time-taken-to-set-a-global-variable/38737>\
**Category:** General\
**Created:** [7 January 2021 17:47 UTC](https://discourse.nodered.org/t/time-taken-to-set-a-global-variable/38737 "2021-01-07T17:47:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [7 January 2021 17:47 UTC](https://discourse.nodered.org/t/time-taken-to-set-a-global-variable/38737/1 "2021-01-07T17:47:14Z")

</div>

Hi all,

I have a change node which sets a global variable, the message then goes on to a function which reads that variable. It seems that the message gets to the function before the variable is set. i.e. the new value isn't there when I read it. If I add a 1sec delay node in between then all is fine.

Does this seem like expected behaviour ?

Running on a pi4 what might be a more realistic minimum time to allow before passing on the message to the function node ?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [7 January 2021 17:50 UTC](https://discourse.nodered.org/t/time-taken-to-set-a-global-variable/38737/2 "2021-01-07T17:50:52Z")

</div>

The Change node doesn't pass the message on until the call to set the value in context has returned - so the Function node should see the value set by the Change node without a delay.

Can you share a simple flow that demonstrates the issue?

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [7 January 2021 18:04 UTC](https://discourse.nodered.org/t/time-taken-to-set-a-global-variable/38737/3 "2021-01-07T18:04:42Z")

</div>

Thanks - so if it's not normal then I will investigate some more.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [7 January 2021 23:34 UTC](https://discourse.nodered.org/t/time-taken-to-set-a-global-variable/38737/4 "2021-01-07T23:34:21Z")

</div>

So I found that my function was running ok but actually its too fast for my browser to see the dynamic changes it makes. These must happen before the page loads so I see the defaults. The delay node allows the page to load and then the function updates the page correctly.

Thanks for your help.

---

<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:** [21 January 2021 23:34 UTC](https://discourse.nodered.org/t/time-taken-to-set-a-global-variable/38737/5 "2021-01-21T23:34:33Z")

</div>

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