# Avoiding race condition in flow context?

**URL:** <https://discourse.nodered.org/t/avoiding-race-condition-in-flow-context/35090>\
**Category:** General\
**Created:** [30 October 2020 22:09 UTC](https://discourse.nodered.org/t/avoiding-race-condition-in-flow-context/35090 "2020-10-30T22:09:29Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [11 December 2020 01:43 UTC](https://discourse.nodered.org/t/avoiding-race-condition-in-flow-context/35090/6 "2020-12-11T01:43:56Z")

</div>

> [@Semmu](#):
>
> I thought about actually sending a `msg` object for each timer and using a variable delay node to delay firing the corresponding action, but that solution lacks the possibility of reseting a timer (i.e. starting it again from the beginning) and cancelling it altogether while it is waiting in the delay node.

I was looking for similar solution, and found out about this:

You can simply use Delay nodes too!  
The trick is, you can give to `msg.reset` a value like "True" and it will automatically cancel all running delays.

 ![kép](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9dc6c651c1a1f7586c645a129a66ae368ba269ba.png)

```auto
[{"id":"64ca47f5.7b75e","type":"inject","z":"37c9a989.495456","name":"Do it now","topic":"","payload":"7","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":100,"wires":[["a49806c2.c5f05","ece3fc93.0f7248"]]},{"id":"a49806c2.c5f05","type":"change","z":"37c9a989.495456","name":"resettt","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":180,"wires":[["6ec487d5.fc2e"]]},{"id":"ece3fc93.0f7248","type":"delay","z":"37c9a989.495456","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":330,"y":100,"wires":[["29498c22.ff4a6c"]]},{"id":"718518ad.73964","type":"inject","z":"37c9a989.495456","name":"stop","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":180,"wires":[["a49806c2.c5f05"]]},{"id":"6ec487d5.fc2e","type":"delay","z":"37c9a989.495456","name":"","pauseType":"delayv","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":700,"y":100,"wires":[["f71e47e6.373058"]]},{"id":"29498c22.ff4a6c","type":"change","z":"37c9a989.495456","name":"sec_change","rules":[{"t":"set","p":"delay","pt":"msg","to":"ido","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"Changed delay to 7000ms","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":100,"wires":[["6ec487d5.fc2e"]]},{"id":"f71e47e6.373058","type":"debug","z":"37c9a989.495456","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"delay","targetType":"msg","x":880,"y":100,"wires":[]}]

```

You can also change the time to wait. _But it's Important:_  
**Wait time** must be given as millisec! 5000 = 5sec

---

_[View the full topic](https://discourse.nodered.org/t/avoiding-race-condition-in-flow-context/35090)._
