# After receiving message generate each second a message for 10 minutes

**URL:** <https://discourse.nodered.org/t/after-receiving-message-generate-each-second-a-message-for-10-minutes/28426>\
**Category:** General\
**Created:** [16 June 2020 18:59 UTC](https://discourse.nodered.org/t/after-receiving-message-generate-each-second-a-message-for-10-minutes/28426 "2020-06-16T18:59:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JSONata](https://avatars.discourse-cdn.com/v4/letter/j/85e7bf/32.png) [@JSONata](https://discourse.nodered.org/u/JSONata)\
**Post date:** [16 June 2020 18:59 UTC](https://discourse.nodered.org/t/after-receiving-message-generate-each-second-a-message-for-10-minutes/28426/1 "2020-06-16T18:59:29Z")

</div>

So after a message arrives (content is irrelevant) a node starts so send for 10 minutes a message each second. How is this possible?

Doing a for loop sending via node.send? [https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously](https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously)  
However there is no build in sleep function in JavaScript. You need a few lines code to use a sleep function. So is there no easier way to achive this task?

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [16 June 2020 19:23 UTC](https://discourse.nodered.org/t/after-receiving-message-generate-each-second-a-message-for-10-minutes/28426/2 "2020-06-16T19:23:10Z")

</div>

Have a look at the [https://flows.nodered.org/node/node-red-contrib-msg-resend](https://flows.nodered.org/node/node-red-contrib-msg-resend) 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:** [16 June 2020 19:47 UTC](https://discourse.nodered.org/t/after-receiving-message-generate-each-second-a-message-for-10-minutes/28426/3 "2020-06-16T19:47:40Z")

</div>

Using the core nodes, you can do it with a pair of Trigger nodes:

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

```auto
[{"id":"ffb4b0dd.5fd2d","type":"trigger","z":"e91e40e3.6bde","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-1","extend":false,"units":"s","reset":"reset","bytopic":"all","topic":"topic","outputs":1,"x":420,"y":720,"wires":[["a53c62cb.19d2e"]]},{"id":"8e18f3ce.54299","type":"trigger","z":"e91e40e3.6bde","name":"","op1":"","op2":"reset","op1type":"nul","op2type":"str","duration":"10","extend":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":250,"y":800,"wires":[["ffb4b0dd.5fd2d"]]},{"id":"a53c62cb.19d2e","type":"debug","z":"e91e40e3.6bde","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":720,"wires":[]},{"id":"36fe03d.6d6aefc","type":"inject","z":"e91e40e3.6bde","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":720,"wires":[["ffb4b0dd.5fd2d","8e18f3ce.54299"]]}]

```

The incoming message goes to both trigger nodes. The top one is configured to resend `1` every second until it receives a `msg.payload` with a value of `"reset"`.  
The bottom trigger node sends nothing initially, waits 10 minutes, then sends a payload of `reset`, which is passed to the top trigger node to stop it.

---

<div class="post-metadata">

**Author:** ![JSONata](https://avatars.discourse-cdn.com/v4/letter/j/85e7bf/32.png) [@JSONata](https://discourse.nodered.org/u/JSONata)\
**Post date:** [17 June 2020 06:01 UTC](https://discourse.nodered.org/t/after-receiving-message-generate-each-second-a-message-for-10-minutes/28426/4 "2020-06-17T06:01:14Z")

</div>

Thanks, I'll use this variant with built in nodes. The [https://flows.nodered.org/node/node-red-contrib-msg-resend](https://flows.nodered.org/node/node-red-contrib-msg-resend) is especially useful if you want to change the intervals at runtime.

---

<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:** [16 August 2020 06:01 UTC](https://discourse.nodered.org/t/after-receiving-message-generate-each-second-a-message-for-10-minutes/28426/5 "2020-08-16T06:01:17Z")

</div>

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