# Execution logic

**URL:** https://discourse.nodered.org/t/execution-logic/92469
**Category:** General
**Created:** [17 October 2024 18:28 UTC](https://discourse.nodered.org/t/execution-logic/92469 "2024-10-17T18:28:23Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)
#### Post date: [17 October 2024 18:28 UTC](https://discourse.nodered.org/t/execution-logic/92469/1 "2024-10-17T18:28:23Z")

</div>

Hi everyone,  
I would like to understand the execution logic of these two functions .....

 ![img1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9c64fae5ba372687c35293c3672364eb29a760fc.png)

function 1405

```auto
const output = [null, null, null, null, null];

output[0] = { payload: 0, topic: "Test" }
output[1] = { payload: 1, topic: "Test" }
output[2] = { payload: 2, topic: "Test" }
output[3] = { payload: 3, topic: "Test" }
output[4] = { payload: 4, topic: "Test" }

return output;

```

function 1406

```auto
const output = [null, null, null, null, null];

output[0] = { payload: 5, topic: "Test" }
output[1] = { payload: 6, topic: "Test" }
output[2] = { payload: 7, topic: "Test" }
output[3] = { payload: 8, topic: "Test" }
output[4] = { payload: 9, topic: "Test" }

return output;

```

If I create and save (deploy) the functions together I have an output with a certain order, if I delete the link and save (deploy) first one then the other the order the order changes.

I have the opportunity to know which is the first function which will be performed and possibly change the order?

---

<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: [17 October 2024 18:35 UTC](https://discourse.nodered.org/t/execution-logic/92469/2 "2024-10-17T18:35:30Z")

</div>

The nodes are generally in the order they are saved in the flow json, so if you delete the first or alter the wires i would be added after the other.  
Why not have one function with all, or use a trigger node set to output second output to a separate output, then you could control which is executed first.

---

<div class="post-metadata">

### Author: ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)
#### Post date: [17 October 2024 18:40 UTC](https://discourse.nodered.org/t/execution-logic/92469/3 "2024-10-17T18:40:02Z")

</div>

So wires have an index ..... ?  
and in this case is performed first the lowest index .... ?

edit:  
ok, It depends on when is connected the wire, this is the order of execution of the function ...  
changing the order change the order of execution ...

---

<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: [17 October 2024 18:56 UTC](https://discourse.nodered.org/t/execution-logic/92469/4 "2024-10-17T18:56:21Z")

</div>

> [@Giamma](#):
>
> Ok, so wires have an index ..... ?

The node the wires are saved in has a index in the flow.json. Any node modified would be added to the end of the flow json.

You could also deploy the modified flow rather than the modified nodes, which may help with keeping order, but not guaranteed.

---

<div class="post-metadata">

### Author: ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)
#### Post date: [17 October 2024 19:01 UTC](https://discourse.nodered.org/t/execution-logic/92469/5 "2024-10-17T19:01:47Z")

</div>

Ok, thank you ....

---

<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: [15 January 2025 19:02 UTC](https://discourse.nodered.org/t/execution-logic/92469/6 "2025-01-15T19:02:29Z")

</div>

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