# Timer between node.send(msg1) and msg(2)

**URL:** <https://discourse.nodered.org/t/timer-between-node-send-msg1-and-msg-2/80936>\
**Category:** General\
**Created:** [30 August 2023 23:48 UTC](https://discourse.nodered.org/t/timer-between-node-send-msg1-and-msg-2/80936 "2023-08-30T23:48:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mick](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mick/32/80990_2.png) [@Mick](https://discourse.nodered.org/u/Mick)\
**Post date:** [30 August 2023 23:48 UTC](https://discourse.nodered.org/t/timer-between-node-send-msg1-and-msg-2/80936/1 "2023-08-30T23:48:34Z")

</div>

I am trying to inject a timer between TTS text for audible output. I have the following nodes set up to turn to set a variable and output a msg for audible on or off. I have noticed that it seems the initial execution of the flow seems to truncate the beginning of the audible text ouput. My nodes are:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fcbd120fcc8aa45e4d5af517a26b7663bd2bc4b8.png)

I have tried to use the following code to pause the output by using a node.send(msg1) and node.send(msg2).

In the flow I have the timer set to 10 seconds and it seems to have no affect. The flow is below. Once again thanks to all who enlighten me.  
Regards

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

```auto
[
    {
        "id": "0ee225efc8925baa",
        "type": "ui_switch",
        "z": "d77d303.180d8d",
        "g": "c7cd7c2d1b8d9238",
        "name": "Audible",
        "label": "<font size = 5> Audible",
        "tooltip": "<font size = 4> Enable Disable Audible Output for vision impaired",
        "group": "e357ef02.ef3cb",
        "order": 1,
        "width": "6",
        "height": "1",
        "passthru": true,
        "decouple": "false",
        "topic": "audible",
        "topicType": "str",
        "style": "",
        "onvalue": "1",
        "onvalueType": "num",
        "onicon": "fa-low-vision fa-2x",
        "oncolor": "red",
        "offvalue": "0",
        "offvalueType": "num",
        "officon": "fa-low-vision fa-2x",
        "offcolor": "gray",
        "animate": true,
        "className": "",
        "x": 380,
        "y": 260,
        "wires": [
            [
                "c2742cad0e367d40"
            ]
        ]
    },
    {
        "id": "c2742cad0e367d40",
        "type": "function",
        "z": "d77d303.180d8d",
        "g": "c7cd7c2d1b8d9238",
        "name": "function 2",
        "func": "var audible = msg.payload\n if (audible === 0){\n global.set('audible', 0)\n msg = {payload:'Audible Off'}\n return msg\n}\nif (audible === 1) {\n global.set('audible', 1) \n var msg1 = { payload: '' } \n var msg2 = { payload: 'Audible On'}\n node.send(msg1)\n new Promise(resolve => setTimeout(resolve, 10000));\n node.send(msg2)\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 580,
        "y": 260,
        "wires": [
            [
                "d30e5efcf5ab139c"
            ]
        ]
    },
    {
        "id": "d30e5efcf5ab139c",
        "type": "ui_audio",
        "z": "d77d303.180d8d",
        "g": "c7cd7c2d1b8d9238",
        "name": "",
        "group": "e357ef02.ef3cb",
        "voice": "Google US English",
        "always": true,
        "x": 760,
        "y": 260,
        "wires": []
    },
    {
        "id": "e357ef02.ef3cb",
        "type": "ui_group",
        "name": "Radios - Control",
        "tab": "4bc17c6e.b74934",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": true,
        "className": ""
    },
    {
        "id": "4bc17c6e.b74934",
        "type": "ui_tab",
        "name": "Station",
        "icon": "fa-tachometer",
        "order": 10,
        "disabled": false,
        "hidden": false
    }
]

```

---

<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:** [31 August 2023 07:10 UTC](https://discourse.nodered.org/t/timer-between-node-send-msg1-and-msg-2/80936/2 "2023-08-31T07:10:45Z")

</div>

To avoid a concurrency situation where multiple messages arrive in quick succession at the input of the function node - you would be better off having no delay and instead, add a delay node after the function node, set to rate limit mode.

However, if you insist on a delay in the function node - you need to await.

```auto
await new Promise(r => setTimeout(r, 10000));

```

---

<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:** [14 September 2023 07:11 UTC](https://discourse.nodered.org/t/timer-between-node-send-msg1-and-msg-2/80936/3 "2023-09-14T07:11:12Z")

</div>

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