# How can i get several values from asynchronous inputs? (object detection & pose detection)

**URL:** <https://discourse.nodered.org/t/how-can-i-get-several-values-from-asynchronous-inputs-object-detection-pose-detection/67779>\
**Category:** General\
**Created:** [16 September 2022 02:02 UTC](https://discourse.nodered.org/t/how-can-i-get-several-values-from-asynchronous-inputs-object-detection-pose-detection/67779 "2022-09-16T02:02:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hero](https://avatars.discourse-cdn.com/v4/letter/h/e47774/32.png) [@hero](https://discourse.nodered.org/u/hero)\
**Post date:** [16 September 2022 02:02 UTC](https://discourse.nodered.org/t/how-can-i-get-several-values-from-asynchronous-inputs-object-detection-pose-detection/67779/1 "2022-09-16T02:02:01Z")

</div>

Im going to make some flow that perform operations based on detected objects and motion.

so first of all, I made that the camera input stream is transmitted to the object recognition node and the pose recognition node in parallel.

but the problem is that the following node after two recognition nodes can't get both of output values at the same time because theses outputs are asynchronous

how can i solve this problem?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 September 2022 06:34 UTC](https://discourse.nodered.org/t/how-can-i-get-several-values-from-asynchronous-inputs-object-detection-pose-detection/67779/2 "2022-09-16T06:34:34Z")

</div>

Welcome to the forum @hero

See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object, which I think it's what you are asking.

---

<div class="post-metadata">

**Author:** ![cameo69](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cameo69/32/66593_2.png) [@cameo69](https://discourse.nodered.org/u/cameo69)\
**Post date:** [16 September 2022 08:09 UTC](https://discourse.nodered.org/t/how-can-i-get-several-values-from-asynchronous-inputs-object-detection-pose-detection/67779/3 "2022-09-16T08:09:33Z")

</div>

How about a function node?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/06db346d1451f8fe8e860f761bc20bd4a3e0a457.png)

```auto
[{"id":"77fb6a686686f25e","type":"inject","z":"6f729596a4b72dd6","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"nothing","payloadType":"str","x":350,"y":320,"wires":[["f334b635cf738b20"]]},{"id":"e22b766ad5f30e6c","type":"inject","z":"6f729596a4b72dd6","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"no_pose","payloadType":"str","x":360,"y":500,"wires":[["6fb7c7ef7790601b"]]},{"id":"1ecf48f75f4bc5be","type":"inject","z":"6f729596a4b72dd6","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"cat","payloadType":"str","x":350,"y":360,"wires":[["f334b635cf738b20"]]},{"id":"373979a7e10313aa","type":"inject","z":"6f729596a4b72dd6","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"sitting","payloadType":"str","x":350,"y":540,"wires":[["6fb7c7ef7790601b"]]},{"id":"a85b801b2b94eb9d","type":"inject","z":"6f729596a4b72dd6","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"walking","payloadType":"str","x":350,"y":580,"wires":[["6fb7c7ef7790601b"]]},{"id":"64a0fa709af412fd","type":"inject","z":"6f729596a4b72dd6","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"dog","payloadType":"str","x":350,"y":400,"wires":[["f334b635cf738b20"]]},{"id":"f334b635cf738b20","type":"change","z":"6f729596a4b72dd6","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"object","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":360,"wires":[["7c02427e5ab1352f"]]},{"id":"6fb7c7ef7790601b","type":"change","z":"6f729596a4b72dd6","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"pose","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":540,"wires":[["7c02427e5ab1352f"]]},{"id":"7c02427e5ab1352f","type":"function","z":"6f729596a4b72dd6","name":"","func":"const valOrReset = function (newVal, oldVal, lastVal, resetVal) {\n return (newVal == oldVal) ? lastVal : resetVal\n}\n\nconst resetObject = 'nothing'\nconst resetPose = 'no_pose'\n\nconst lastObject = flow.get('lastObject') || resetObject\nconst lastPose = flow.get('lastPose') || resetPose\n\nlet newObject\nlet newPose\n\nif (msg.topic == 'object') {\n newObject = msg.payload\n flow.set('lastObject', newObject)\n newPose = valOrReset(newObject, lastObject, lastPose, resetPose)\n} else {\n if (msg.topic == 'pose') {\n newPose = msg.payload\n flow.set('lastPose', newPose)\n //newObject = valOrReset(newPose, lastPose, lastObject, resetObject)\n newObject = lastObject\n } else {\n msg.payload = { 'object': lastObject, 'pose': lastPose }\n return msg;\n }\n\n}\n\nmsg.payload = { 'object': newObject, 'pose': newPose }\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":440,"wires":[["cc032979ee6f1822"]]},{"id":"cc032979ee6f1822","type":"debug","z":"6f729596a4b72dd6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":440,"wires":[]}]

```

Gives you in payload an object like this:

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

EDIT: corrected function to keep old Object if only pose changed

---

<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:** [16 September 2022 08:13 UTC](https://discourse.nodered.org/t/how-can-i-get-several-values-from-asynchronous-inputs-object-detection-pose-detection/67779/4 "2022-09-16T08:13:53Z")

</div>

Or write zero code and use the join node as @Colin suggested 😉

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

```auto
[{"id":"77fb6a686686f25e","type":"inject","z":"8fb7704d922a7884","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"nothing","payloadType":"str","x":1094.000087738037,"y":400.0000581741333,"wires":[["f334b635cf738b20"]]},{"id":"e22b766ad5f30e6c","type":"inject","z":"8fb7704d922a7884","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"no_pose","payloadType":"str","x":1104.000087738037,"y":580.0000581741333,"wires":[["6fb7c7ef7790601b"]]},{"id":"1ecf48f75f4bc5be","type":"inject","z":"8fb7704d922a7884","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"cat","payloadType":"str","x":1094.000087738037,"y":440.0000581741333,"wires":[["f334b635cf738b20"]]},{"id":"373979a7e10313aa","type":"inject","z":"8fb7704d922a7884","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"sitting","payloadType":"str","x":1094.000087738037,"y":620.0000581741333,"wires":[["6fb7c7ef7790601b"]]},{"id":"a85b801b2b94eb9d","type":"inject","z":"8fb7704d922a7884","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"walking","payloadType":"str","x":1094.000087738037,"y":660.0000581741333,"wires":[["6fb7c7ef7790601b"]]},{"id":"64a0fa709af412fd","type":"inject","z":"8fb7704d922a7884","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"dog","payloadType":"str","x":1094.000087738037,"y":480.0000581741333,"wires":[["f334b635cf738b20"]]},{"id":"f334b635cf738b20","type":"change","z":"8fb7704d922a7884","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"object","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1284.000087738037,"y":440.0000581741333,"wires":[["e755a445b5658da5"]]},{"id":"6fb7c7ef7790601b","type":"change","z":"8fb7704d922a7884","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"pose","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1284.000087738037,"y":620.0000581741333,"wires":[["e755a445b5658da5"]]},{"id":"cc032979ee6f1822","type":"debug","z":"8fb7704d922a7884","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1630,"y":520,"wires":[]},{"id":"e755a445b5658da5","type":"join","z":"8fb7704d922a7884","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1470,"y":520,"wires":[["cc032979ee6f1822"]]}]

```

---

<div class="post-metadata">

**Author:** ![cameo69](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cameo69/32/66593_2.png) [@cameo69](https://discourse.nodered.org/u/cameo69)\
**Post date:** [16 September 2022 08:19 UTC](https://discourse.nodered.org/t/how-can-i-get-several-values-from-asynchronous-inputs-object-detection-pose-detection/67779/5 "2022-09-16T08:19:08Z")

</div>

> [@Steve-Mcl](#):
>
> Or write zero code and use the join node as @Colin suggested 😉

Sure, you could. But it behaves slightly different; especially does not reset the pose if object changed.  
Guess it depends what the user really needs (?) 🙂

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 September 2022 08:32 UTC](https://discourse.nodered.org/t/how-can-i-get-several-values-from-asynchronous-inputs-object-detection-pose-detection/67779/6 "2022-09-16T08:32:04Z")

</div>

> [@cameo69](#):
>
> does not reset the pose

in the join node turn off "and every subsequent message" and add a suitable timeout instead such that both messages would arrive within that timeframe.

---

<div class="post-metadata">

**Author:** ![hero](https://avatars.discourse-cdn.com/v4/letter/h/e47774/32.png) [@hero](https://discourse.nodered.org/u/hero)\
**Post date:** [16 September 2022 08:53 UTC](https://discourse.nodered.org/t/how-can-i-get-several-values-from-asynchronous-inputs-object-detection-pose-detection/67779/8 "2022-09-16T08:53:54Z")

</div>

thanks! for your reply 🙂 lol

---

<div class="post-metadata">

**Author:** ![hero](https://avatars.discourse-cdn.com/v4/letter/h/e47774/32.png) [@hero](https://discourse.nodered.org/u/hero)\
**Post date:** [16 September 2022 08:55 UTC](https://discourse.nodered.org/t/how-can-i-get-several-values-from-asynchronous-inputs-object-detection-pose-detection/67779/9 "2022-09-16T08:55:14Z")

</div>

thanks! for your reply 🙂 i also thought about using func but it was hard 🙂

---

<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:** [30 September 2022 08:55 UTC](https://discourse.nodered.org/t/how-can-i-get-several-values-from-asynchronous-inputs-object-detection-pose-detection/67779/10 "2022-09-30T08:55:48Z")

</div>

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