# Synchronized msg in flow , one by one

**URL:** <https://discourse.nodered.org/t/synchronized-msg-in-flow-one-by-one/20716>\
**Category:** General\
**Created:** [22 January 2020 08:50 UTC](https://discourse.nodered.org/t/synchronized-msg-in-flow-one-by-one/20716 "2020-01-22T08:50:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![erezasmra](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@erezasmra](https://discourse.nodered.org/u/erezasmra)\
**Post date:** [22 January 2020 08:50 UTC](https://discourse.nodered.org/t/synchronized-msg-in-flow-one-by-one/20716/1 "2020-01-22T08:50:31Z")

</div>

hello all,  
I really newbie in node-red,  
my question is ...  
I got a flow that received event msg,  
I want that every msg finish the flow and after a new msg start the flow.

tnx a lot ,

for example  
msg start ----\>msg finish then msg1 start ------\> msg1 finish

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 January 2020 09:04 UTC](https://discourse.nodered.org/t/synchronized-msg-in-flow-one-by-one/20716/2 "2020-01-22T09:04:22Z")

</div>

You can use `node-red-contrib-semaphore` to ensure that only one message is allowed through at once. Depending on exactly what is in the flow there may be simpler ways. Can you give us an idea of what is there and why you need to do this?

---

<div class="post-metadata">

**Author:** ![erezasmra](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@erezasmra](https://discourse.nodered.org/u/erezasmra)\
**Post date:** [22 January 2020 09:08 UTC](https://discourse.nodered.org/t/synchronized-msg-in-flow-one-by-one/20716/3 "2020-01-22T09:08:57Z")

</div>

hey Colin ,  
tnx for answer so fast.  
the reason that I need that is to avoid a collision in my flow variable's

---

<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:** [22 January 2020 09:40 UTC](https://discourse.nodered.org/t/synchronized-msg-in-flow-one-by-one/20716/4 "2020-01-22T09:40:50Z")

</div>

> [@erezasmra](#):
>
> I need that is to avoid a collision in my flow variable's

You should not store per-message state in flow context. If there is a piece of state you want to associate with a message, you should set it as a property of the message as it passes through the flow. This would remove the restriction of having one message active in your flow at one time.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 January 2020 09:44 UTC](https://discourse.nodered.org/t/synchronized-msg-in-flow-one-by-one/20716/5 "2020-01-22T09:44:03Z")

</div>

> [@erezasmra](#):
>
> avoid a collision in my flow variable's

Here is a simple example showing how it can be done without using context

```auto
[{"id":"d6c7b712.a26a7","type":"inject","z":"5bb5a6a6.97527","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":413,"wires":[["d0f22ac1.1031b8"]]},{"id":"d0f22ac1.1031b8","type":"function","z":"5bb5a6a6.97527","name":"Save timestamp","func":"// save the data we want to keep in msg.savedData\nmsg.savedData = msg.payload\nmsg.payload = \"some value\"\nreturn msg;","outputs":1,"noerr":0,"x":262,"y":414,"wires":[["70e6e940.498ae"]]},{"id":"70e6e940.498ae","type":"delay","z":"5bb5a6a6.97527","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":427,"y":413,"wires":[["3f17330b.ffe3e4"]]},{"id":"3f17330b.ffe3e4","type":"function","z":"5bb5a6a6.97527","name":"Pick it up again","func":"// pick up the saved value for use now\nmsg.payload = \"msg.savedData is \" + msg.savedData\nreturn msg;","outputs":1,"noerr":0,"x":603,"y":413,"wires":[["ae37c7da.33b8f"]]},{"id":"ae37c7da.33b8f","type":"debug","z":"5bb5a6a6.97527","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":577,"y":523,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![erezasmra](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@erezasmra](https://discourse.nodered.org/u/erezasmra)\
**Post date:** [22 January 2020 09:54 UTC](https://discourse.nodered.org/t/synchronized-msg-in-flow-one-by-one/20716/6 "2020-01-22T09:54:51Z")

</div>

Tnx a lot Colin , the issue fixed 🙂
