# Newbie question: creating building-blocks that I can call from multiple flows

**URL:** <https://discourse.nodered.org/t/newbie-question-creating-building-blocks-that-i-can-call-from-multiple-flows/16775>\
**Category:** General\
**Created:** [16 October 2019 15:08 UTC](https://discourse.nodered.org/t/newbie-question-creating-building-blocks-that-i-can-call-from-multiple-flows/16775 "2019-10-16T15:08:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![moti\_r](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/moti_r/32/12768_2.png) [@moti\_r](https://discourse.nodered.org/u/moti_r)\
**Post date:** [16 October 2019 15:08 UTC](https://discourse.nodered.org/t/newbie-question-creating-building-blocks-that-i-can-call-from-multiple-flows/16775/1 "2019-10-16T15:08:00Z")

</div>

Hi,

Have been working with node-red for the past couple of weeks, and have successfully migrated from [hass.io](http://hass.io), extremely happy!

A newbie question:

I sometimes have a set of nodes that combine into a "function" - for example, the input payload is the name of a radio station to stream, and the nodes interpret that into a URL and then send it to the android streamer for streaming.

I call this "function" from multiple flows (some handle HTTP requests, some handle IR signals and some for automation) so I've put a link-in node at the beginning, and then when I need to set a radio station from any flow, I just set the payload and use a link-out node to attach to the radio module.

All's great, but link-out is asynchronous and does not return, so I have no way to do something when the radio stuff is done.

Is there a way to pack a set of nodes into a callable "module" of some sort, and call it synchronously?

Thanks!  
Moti

---

<div class="post-metadata">

**Author:** ![juancuellar](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@juancuellar](https://discourse.nodered.org/u/juancuellar)\
**Post date:** [16 October 2019 15:16 UTC](https://discourse.nodered.org/t/newbie-question-creating-building-blocks-that-i-can-call-from-multiple-flows/16775/2 "2019-10-16T15:16:18Z")

</div>

I am not sure what you need as i am a newbie myself but what i think might help you is this, i found out that you can check the topic that goes into a function and then work with the payload as you wish so i am using it to store some variables inside said function node this is an example of the code i am using

if (msg.topic == "delay") {  
if (msg.payload \>=1 && msg.payload\<120)  
{context.delay=msg.payload_60000;  
}  
else{context.delay=5_60000;  
}  
return null;  
}

if (msg.topic == "enable") {  
context.state = msg.payload;  
return null;  
}

so if the topic i get is enable i use the payload to set a boolean variable  
if the topic is delay i use it to set a integer variable.

I hope this is of any help to you

---

<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 October 2019 15:45 UTC](https://discourse.nodered.org/t/newbie-question-creating-building-blocks-that-i-can-call-from-multiple-flows/16775/3 "2019-10-16T15:45:00Z")

</div>

Have a look at subflows and see if that does what you want.  
[https://nodered.org/docs/user-guide/editor/workspace/subflows](https://nodered.org/docs/user-guide/editor/workspace/subflows)

---

<div class="post-metadata">

**Author:** ![moti\_r](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/moti_r/32/12768_2.png) [@moti\_r](https://discourse.nodered.org/u/moti_r)\
**Post date:** [16 October 2019 20:03 UTC](https://discourse.nodered.org/t/newbie-question-creating-building-blocks-that-i-can-call-from-multiple-flows/16775/4 "2019-10-16T20:03:23Z")

</div>

This is exactly what I wanted!  
Thank you!  
I've searched a lot, can't believe I missed it...  
Thanks again, Colin.
