Cancelling

Cancelling a function is important to reduce working memory and to free up resources.
Excel will automatically cancel an asynchronous function in the following situations:
The user edits or deletes a cell that references the function
One of the arguments (inputs) for the function changes. In this case, a new function call is triggered in addition to the cancelation.
The user triggers recalculation manually. As with the above case, a new function call is triggered in addition to the cancelation.


Every custom function should define an onCanceled function on the caller object.


function method_to_call(increment, caller){ 
    var result = 0;
    setInterval(function(){
         result += increment;
         caller.setResult(result);
    }, 1000);

    caller.onCanceled = function(){
        clearInterval(timer);
    }
}


© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext