I have a Lightning action call inside a recursive setTimeout
call. I call the action immediately and then every 3 seconds until the result it not null
.
I see my console.log('tick');
immediately. But I don't see my result (in either the if or the else block) until my window (or tab) loses focus. As soon as it does lose focus, it returns immediately and I see my results as intended.
It may or may not be worth mentioning this action call is inside the callback (the then(...) of a previous action, as denoted by my variable action2
.
It also may or may not be worth mentioning that this is all happening on a Lightning Out site.
Also, I'm following the excellent action execution pattern as described by the infamous Bob Buzzard here: http://bobbuzzard.blogspot.com/2016/12/javascript-promises-in-lightning_30.html
setTimeout(function tick() {
console.log('tick');
self.executeAction(component, action2)
.then($A.getCallback(result => {
if (result) {
console.log(result);
} else {
console.log('not yet...');
setTimeout(tick, 3000)
}
}));
}, 0);
It undoubtedly has something to do with a missing or improperly placed $A.getcallBack()
?
Many thanks.