Let’s say we have some Promise for we knew it resolves at some point. Now I have sync code (ag. no await possible) called repeatedly (eg. onAnimationFrame). How to use the result of the promise there, if it is fullfilled?
Like (JS pseudocode):
let promise=FetchSomething();
let updater = ()=>{
drawSomething();
if(promise IS FULLFILLED) // how to know if fullfilled?
drawThing(RESULT OF promise); // how to get the result here?
requestAnimationFrame(updater);
}
updater();
2
Answers
The easiest way is to set a variable yourself:
You can do the same with the result, i.e.:
Perhaps this simple promise using your names will illustrate: