Skip to content

Defining utility functions for re-use in a function node#5494

Draft
Steve-Mcl wants to merge 13 commits intodevfrom
function-call-subroutines
Draft

Defining utility functions for re-use in a function node#5494
Steve-Mcl wants to merge 13 commits intodevfrom
function-call-subroutines

Conversation

@Steve-Mcl
Copy link
Copy Markdown
Contributor

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Proposed changes

As discussed on discourse: https://discourse.nodered.org/t/defining-utility-functions-for-re-use-in-a-function-node/100294)

A way of generating re-usable logic that a function node can call without leaving the function execution environment.

Simplifying logic reuse is a commonly requested feature. This PR provides a means that fits with the flow based paradigm in that it permits calling re-usable logic in a function node but also utilises the well established subroutines visual flow using link-in ~ link-out nodes to build the re-usable logic.

Example

const returnMsg = await node.linkcall('nested-1', msg, { timeout: 1000 })
return returnMsg;
image

In the PR

  • Added node.linkcall to the function node vm
    • linkcall(target: string, msg: object, options?: { timeout?: number; clone?: boolean; [key: string]: any }): Promise<object>;
  • Some logic from link nodes was refactored to common runtime code
  • Example flows were updated to demonstrate functionality

Tests added:

link call from function
      ✔ should call subroutine on same tab by name and get response
      ✔ should call subroutine on different tab by name and get response
      ✔ should call subroutine on same tab by node id and get response
      ✔ should call subroutine on different tab by node id and get response
      ✔ should call subroutine on same tab even when there are same named targets on other tabs
      ✔ should call nested subroutines
      ✔ should timeout waiting for link return (507ms)
      ✔ should raise error for non-existent target subroutine
      ✔ should raise error due to multiple targets on same tab
      ✔ should raise error due to multiple targets on different tabs

Demo flows for trying out the PR

I will attached demo flows in follow up

Checklist

  • I have read the contribution guidelines
  • For non-bugfix PRs, I have discussed this change on the forum/slack team.
  • I have run npm run test to verify the unit tests pass
  • I have added suitable unit tests to cover the new/changed functionality

@Steve-Mcl Steve-Mcl marked this pull request as draft February 23, 2026 09:15
@Steve-Mcl
Copy link
Copy Markdown
Contributor Author

Steve-Mcl commented Feb 23, 2026

PR In draft while remaining tasks are completed:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant