help you fix your problem I think I understand what you're asking. You want to know if a function can place a function on the defer stack of the caller. The answer to that is no. One possible solution to this is to have the function that wants to defer something return that function to the caller and have the caller do the defer. For example:
this one helps. Ok I just figured out. If you pass any parameters to the defer func (like the 2nd defer function above), those parameters are evaluated when the defer function is deferred, not when they are executed. That means in my example err is still nil and has not been assigned to a new error yet. on the other hand, in 1st defer above, err is not a parameter, but a variable in function a, and when 1st defer is executed, it has already been assigned to a new error.
Does Azure functions Fan-out / Fan-in func always have better performance than just running a single function thread?
around this issue Obviously, if your activity to be executed multiple times is something lightweight (e.g. adding numbers), it's going to be faster to execute it just within the single Function without remote calls, queues, and leaving the process whatsoever. Fan-out / Fan-in pattern is only valid for expensive computations or IO operations that can benefit from parallelization.