# Is this a good way to add delay for each msg

**URL:** <https://discourse.nodered.org/t/is-this-a-good-way-to-add-delay-for-each-msg/21512>\
**Category:** General\
**Created:** [10 February 2020 17:43 UTC](https://discourse.nodered.org/t/is-this-a-good-way-to-add-delay-for-each-msg/21512 "2020-02-10T17:43:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhishekjaiswalraw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/abhishekjaiswalraw/32/16377_2.png) [@abhishekjaiswalraw](https://discourse.nodered.org/u/abhishekjaiswalraw)\
**Post date:** [10 February 2020 17:43 UTC](https://discourse.nodered.org/t/is-this-a-good-way-to-add-delay-for-each-msg/21512/1 "2020-02-10T17:43:30Z")

</div>

```auto
[{"id":"5273c8b7.2e5bb8","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"7066c53d.b7f40c","type":"function","z":"5273c8b7.2e5bb8","name":"++","func":"if ( (msg.i += 1) < msg.items.length ) return msg;\n","outputs":1,"x":550,"y":380,"wires":[["ecca47f3.6a80a8"]]},{"id":"ecca47f3.6a80a8","type":"function","z":"5273c8b7.2e5bb8","name":"for each item"[{"id":"5273c8b7.2e5bb8","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"7066c53d.b7f40c","type":"function","z":"5273c8b7.2e5bb8","name":"++","func":"if ( (msg.i += 1) < msg.items.length ) return msg;\n","outputs":1,"x":550,"y":380,"wires":[["ecca47f3.6a80a8"]]},{"id":"ecca47f3.6a80a8","type":"function","z":"5273c8b7.2e5bb8","name":"for each item","func":"if( msg.i == undefined ) msg.i = 0;\nif( msg.items == undefined ) msg.items = msg.payload;\n\nmsg.payload = msg.items[msg.i];\n\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":260,"wires":[["7ce357bb.ec4f18"]]},{"id":"dd576484.19f8d8","type":"inject","z":"5273c8b7.2e5bb8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":280,"wires":[["1879bff4.42ad5"]]},{"id":"1879bff4.42ad5","type":"function","z":"5273c8b7.2e5bb8","name":"arr","func":"msg.payload = [10,12,16];\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":280,"wires":[["ecca47f3.6a80a8"]]},{"id":"7ce357bb.ec4f18","type":"delay","z":"5273c8b7.2e5bb8","name":"","pauseType":"delay","timeout":"4","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":720,"y":260,"wires":[["7066c53d.b7f40c","e4fde399.d9c3c"]]},{"id":"e4fde399.d9c3c","type":"debug","z":"5273c8b7.2e5bb8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":180,"wires":[]}]![Screenshot from 2020-02-10 23-10-32|690x372](upload://83GJxaRhHmaFXia7fumwyNm5CIG.png) ,"func":"if( msg.i == undefined ) msg.i = 0;\nif( msg.items == undefined ) msg.items = msg.payload;\n\nmsg.payload = msg.items[msg.i];\n\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":260,"wires":[["7ce357bb.ec4f18"]]},{"id":"dd576484.19f8d8","type":"inject","z":"5273c8b7.2e5bb8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":280,"wires":[["1879bff4.42ad5"]]},{"id":"1879bff4.42ad5","type":"function","z":"5273c8b7.2e5bb8","name":"arr","func":"msg.payload = [10,12,16];\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":280,"wires":[["ecca47f3.6a80a8"]]},{"id":"7ce357bb.ec4f18","type":"delay","z":"5273c8b7.2e5bb8","name":"","pauseType":"delay","timeout":"4","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":720,"y":260,"wires":[["7066c53d.b7f40c","e4fde399.d9c3c"]]},{"id":"e4fde399.d9c3c","type":"debug","z":"5273c8b7.2e5bb8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":180,"wires":[]}]![Screenshot from 2020-02-10 23-10-32|690x372](upload://83GJxaRhHmaFXia7fumwyNm5CIG.png) 

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [10 February 2020 17:51 UTC](https://discourse.nodered.org/t/is-this-a-good-way-to-add-delay-for-each-msg/21512/2 "2020-02-10T17:51:00Z")

</div>

Please give more than just a flow because that forces people to load it and, quite frankly, many of us don't have time to do that for every question.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [10 February 2020 19:43 UTC](https://discourse.nodered.org/t/is-this-a-good-way-to-add-delay-for-each-msg/21512/3 "2020-02-10T19:43:05Z")

</div>

Also your flow is not importable. Please read [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [10 February 2020 19:53 UTC](https://discourse.nodered.org/t/is-this-a-good-way-to-add-delay-for-each-msg/21512/4 "2020-02-10T19:53:31Z")

</div>

beat me to it, its like there is a parts of a flow pasted several times with the same screenshot pasted into the middle and at the end. All wrapped in ````` code markers `````

this is the screen shots I pulled out of the code block...

 ![Screenshot from 2020-02-10 23-10-32](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/8/387c271c33847c9cc27cf0e09c1b22a0ebab2a02.png)

it looks like he is looping through an array and sending messages delayed by 4s.

@abhishekjaiswalraw I would say, no (IMO), not the ideal way to do that. You'd be better sending the array of items in one go via a delay node set to "rate limit 1msg / 4s"

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/b/7b6aaaf6aa69aed4f5110510f0d5bea207b5579b.png)

---

<div class="post-metadata">

**Author:** ![abhishekjaiswalraw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/abhishekjaiswalraw/32/16377_2.png) [@abhishekjaiswalraw](https://discourse.nodered.org/u/abhishekjaiswalraw)\
**Post date:** [11 February 2020 05:08 UTC](https://discourse.nodered.org/t/is-this-a-good-way-to-add-delay-for-each-msg/21512/5 "2020-02-11T05:08:18Z")

</div>

what is name of this node

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [11 February 2020 07:04 UTC](https://discourse.nodered.org/t/is-this-a-good-way-to-add-delay-for-each-msg/21512/6 "2020-02-11T07:04:04Z")

</div>

> [@abhishekjaiswalraw](#):
>
> what is name of this node

> [@Steve-Mcl](#):
>
> delay node

I also highlighted it in the screen shot
