Giamma
13 September 2023 13:24
1
Hi, I try to explain .....
this is the code:
const output = [null, null];
const x = msg.payload
if (x == 1)
{
output[0] = { payload: "uno" }
output[1] = { payload: "due" }
setTimeout(() => { node.send(output[0]) }, 6000)
setTimeout(() => { node.send(output[1]) }, 0)
}
I have the correct delay but for the same node (0) instead of "uno" for output [0]
and "due" for output [1]
Where am I wrong?
That output looks correct to me. You are sending output[1]
after a zero ms timeout so it appears first and output[0]
after a 6s delay. What did you expect?
Of course, a timeout with a zero delay is a bit pointless I think.
Giamma
13 September 2023 13:38
3
The second image ....
both node: 0
Instead
output[1] = { payload: "due" }
should be node: 1
Giamma:
should be node: 1
Urm, afraid not. Because you've only passed 1 element of output
to each node.send. So both messages will appear from the top port of the function node and go to the debug marked 0
on your flow.
I think what you meant to do was something like this:
const output = [null, null];
const x = msg.payload
if (x == 1)
{
output[0] = { payload: "uno" }
output[1] = { payload: "due" }
setTimeout(() => { node.send( [output[0], null] ) }, 6000)
setTimeout(() => { node.send( [null, output[1]] ) }, 0)
}
If, instead, you did
const output = [null, null];
const x = msg.payload
if (x == 1)
{
output[0] = { payload: "uno" }
output[1] = { payload: "due" }
setTimeout(() => { node.send(output) }, 6000)
setTimeout(() => { node.send(output) }, 0)
}
You would get 4 outputs.
E1cid
13 September 2023 13:47
5
Try
const output = [[null,null], [null,null]];
const x = msg.payload
if (x == 1)
{
output[0][0] = { payload: "uno" }
output[1][1] = { payload: "due" }
setTimeout(() => { node.send(output[0]) }, 6000)
setTimeout(() => { node.send(output[1]) }, 0)
}
OR
const output = [[null],[null]]
const x = msg.payload
if (x == 1)
{
output[0].unshift({ payload: "uno" })
output[1].push({ payload: "due" })
setTimeout(() => { node.send(output[0]) }, 6000)
setTimeout(() => { node.send(output[1]) }, 0)
}
1 Like
Giamma
13 September 2023 13:48
6
Yes .....
const output = [null, null];
const x = msg.payload
if (x == 1)
{
output[0] = { payload: "uno" }
output[1] = { payload: "due" }
setTimeout(() => { node.send( [output[0], null] ) }, 6000)
setTimeout(() => { node.send( [null, output[1]] ) }, 0)
}
This is correct for me.
Thank you very much .....
system
Closed
27 September 2023 13:48
7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.