I have an angularjs application launched inside an overlay from another non Angular application. In the application, i am hitting a xhr request from inside a setTimeout() with delay of say 10 secs. The xhr request is sent to a device attached to system and performs an action on device. After calling setTimeout(), i need to hide the overlay (display:hidden) and unmount my application from DOM entirely without waiting for timeout delay. [refer code].
The problem is, xhr request operation is executed after set delay(checked using breakpoint), its response (a promise) is logged in console. But, promise callbacks - resolve or rejected are not executed, network tab does not show the http call, device does not perform desired action.
if i remove/comment unMountOverlay(), then code works as expected. Also i cant wait for timeout delay to execute unMountOverlay().
callTimeOut() { /** called on some user action */
var self = this;
console.log("Calling Timeout"); /** Getting printed */
setTimeout(()=>{
ayncOperation().then(()=>{
console.log("Success"); /** Not Getting printed */
},
()=>{
console.log("Failed"); /** Not Getting printed */
})
},
10000);
unMountOverlay(); // set display:none; Unmount application from DOM
}
ayncOperation(){
let promise = this.request(config.launch); /** call for async operation to device */
console.log(promise); /** Getting printed */ /** a promise object containing methods - then catch finally .. */
return promise;
}
i have 2 questions .. 1) When xhr request is getting executed and response promised is logged in console, why the http request is not visible in network tab ? 2) When a promise object is being returned and logged in console, why resolution/rejection callbacks are not executed.
As per my understanding, when runtime engine finds settimeout(), it starts the counter, adds settimeout to stack, executes code further. When timeout delay is over, pops the timeout callback and executes the same, even when the rest of application has exited. Please correct me.
P.S. My application only works in IE.