cleanupBeforeDestroyComplete function

If your task defined a cleanupBeforeDestroy function, call the cleanupBeforeDestroyComplete function to inform z/OSMF core that your cleanup actions are complete and that your task is ready to be closed.

Invoking the function

To call the cleanupBeforeDestroyComplete function, use the syntax shown in Figure 1.

Figure 1. Syntax to use to call the cleanupBeforeDestroyComplete function
win.global.zosmfExternalTools.cleanupBeforeDestroyComplete(obj);
where,
obj
Name of the parameter that was passed to the cleanupBeforeDestroy function.

The cleanupBeforeDestroyComplete function must be called after your cleanupBeforeDestroy function completes. Otherwise, z/OSMF might close the task before the cleanup actions are complete.

For example, if your cleanupBeforeDestroy function is performing an XMLHttpRequest (XHR) call, the cleanupBeforeDestroyComplete function must be called at the end of the XHR call and not immediately after the XHR call is issued.

Note: If your task does not call the cleanupBeforeDestroyComplete function within one second after z/OSMF invokes your cleanupBeforeDestroy function or if errors occur with the cleanupBeforeDestroy function, z/OSMF will close your task after one second elapses.

Example

Figure 2. Sample code for the cleanupBeforeDestroyComplete function
win.global.zosmfExternalTools.cleanupBeforeDestroy = function(obj) {
   
  //A synchronous cleanup method that cleans up objects on the client
  //to free up memory.
  myApi.cleanupMethod();
   
  //Inform z/OSMF core that the cleanup actions are complete 
  //and that the task is ready to be closed.
  win.global.zosmfExternalTools.cleanupBeforeDestroyComplete(obj);
};

If myApi.cleanupMethod() is an asynchronous method, call the cleanupBeforeDestroyComplete function after the asynchronous action completes. Otherwise, the asynchronous method might not have time to complete.