[SalesForce] Why is an action callback not getting called

I have a helper function called via a controller function and am calling it in two circumstances:

save : function(component, event, helper) {
    var action = component.get("c.replaceAllChildrenOfType");
    action.setParams({...});
    action.setCallback(this, function(response) {
        console.log('callback');
    });
    $A.enqueueAction(action);
    console.log('enqueued');
},

One circumstance is from a button on the component:

<lightning:button label="Temporary Save" onclick="{! c.save }"/>

where things go as expected with "enqueued" logged and then "callback" logged shortly afterwards with the server-side update having been done.

The other circumstance is via a method invoked from a separate component:

<aura:method name="save" action="{! c.save }"/>

where things do not go as expected with "enqueued" logged and then no "callback" logged at all with the server-side update having been done.

Can anyone explain?

PS

Further digging – for the aura:method case, the callback does happen if the call is made from a button click but does not happen if the call is made handling an application event.

Will delete this if it turns out to be something really daft on my part.

Best Answer

As commenters have suggested, the cause is other code of mine where the component enqueuing the action is getting (very promptly) destroyed before the callback can complete because the component is being replaced by a different one in the body of the parent. Makes sense: just makes my life a bit harder...