This solution is working only if you want to call the function from different places but NOT simultaneously.
Just make your function as a simple “Collapse nodes” and expose the parameters you want to use as you’r function’s signature.
Then, make a custom event that calls it with those parameters, as so :
And then, call it from ever you want, as so :
Hope you find it useful