# Inject node with interval - How to wait for flow to finish before injecting again?

**URL:** <https://discourse.nodered.org/t/inject-node-with-interval-how-to-wait-for-flow-to-finish-before-injecting-again/70325>\
**Category:** General\
**Created:** [9 November 2022 13:51 UTC](https://discourse.nodered.org/t/inject-node-with-interval-how-to-wait-for-flow-to-finish-before-injecting-again/70325 "2022-11-09T13:51:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Omrizn](https://avatars.discourse-cdn.com/v4/letter/o/f05b48/32.png) [@Omrizn](https://discourse.nodered.org/u/Omrizn)\
**Post date:** [9 November 2022 13:51 UTC](https://discourse.nodered.org/t/inject-node-with-interval-how-to-wait-for-flow-to-finish-before-injecting-again/70325/1 "2022-11-09T13:51:29Z")

</div>

Hello,

I have a flow that I want to run every X seconds, so I'm using the "Inject" node and set interval for X seconds, my goal is to run the flow only if the flow has finished to run,  
the problem is that the flow running again before the flow finished and it causing unwanted behavior,  
so my question is how can I run a flow every X seconds but only if the flow has finished running?

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 November 2022 14:28 UTC](https://discourse.nodered.org/t/inject-node-with-interval-how-to-wait-for-flow-to-finish-before-injecting-again/70325/2 "2022-11-09T14:28:10Z")

</div>

Hi and welcome.  
All depends on timing you wish after the flow finishes.  
here are 2 examples of possible solutions

```auto
[{"id":"b2cd414314d6cb69","type":"inject","z":"452103ea51141731","name":"stop","props":[{"p":"reset","v":"true","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":150,"y":3540,"wires":[["8a582f90b300bcda"]]},{"id":"8a582f90b300bcda","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"finished","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":3540,"wires":[["652b0d3ab2b55b71"]]},{"id":"652b0d3ab2b55b71","type":"delay","z":"452103ea51141731","name":"simulate flow time","pauseType":"random","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"4","randomLast":"6","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":470,"y":3480,"wires":[["a00362e6d6b9affd"]]},{"id":"d27964c10afa5663","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"finished","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":3420,"wires":[["652b0d3ab2b55b71"]]},{"id":"a00362e6d6b9affd","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"delete","p":"finished","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":3420,"wires":[["a80776679f1372bf"]]},{"id":"b7800bad515d4db1","type":"switch","z":"452103ea51141731","name":"","property":"finished","propertyType":"flow","rules":[{"t":"istype","v":"undefined","vt":"undefined"}],"checkall":"true","repair":false,"outputs":1,"x":230,"y":3420,"wires":[["d27964c10afa5663"]]},{"id":"a80776679f1372bf","type":"debug","z":"452103ea51141731","name":"debug 107","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":3460,"wires":[]},{"id":"49588608ed5577a0","type":"inject","z":"452103ea51141731","name":"test","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"2","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":3420,"wires":[["b7800bad515d4db1"]]},{"id":"981b57957a5a55ec","type":"inject","z":"452103ea51141731","name":"stop","props":[{"p":"reset","v":"true","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":150,"y":3580,"wires":[["cdec8f187c0b9749"]]},{"id":"cdec8f187c0b9749","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"delete","p":"finished","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":3580,"wires":[[]]},{"id":"ae660bb3eba7402a","type":"inject","z":"452103ea51141731","name":"reset","props":[{"p":"reset","v":"true","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":150,"y":3320,"wires":[["eade73defeaf2348"]]},{"id":"eade73defeaf2348","type":"trigger","z":"452103ea51141731","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"5","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":320,"y":3320,"wires":[["27cc2aae95087f4f"]]},{"id":"1c0bb849507f28ad","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"test","payloadType":"str","x":170,"y":3260,"wires":[["eade73defeaf2348"]]},{"id":"27cc2aae95087f4f","type":"delay","z":"452103ea51141731","name":"simulate flow time","pauseType":"random","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"4","randomLast":"6","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":390,"y":3220,"wires":[["a15b280990b32f57"]]},{"id":"a15b280990b32f57","type":"function","z":"452103ea51141731","name":"function 17","func":"return [msg,msg];","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":3260,"wires":[["543d77c6f929e577"],["eade73defeaf2348"]]},{"id":"543d77c6f929e577","type":"debug","z":"452103ea51141731","name":"debug 106","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":3260,"wires":[]}]

```

---

<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:** [8 January 2023 14:28 UTC](https://discourse.nodered.org/t/inject-node-with-interval-how-to-wait-for-flow-to-finish-before-injecting-again/70325/3 "2023-01-08T14:28:23Z")

</div>

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