How to wait until promise finishes before continuing the loop

var p = promiseReturnedFromAFunction();
var time = new Date().getTime();
var user="undefined";

p.then(() => {
   while(user === 'undefined' && Math.abs(time - new Date().getTime()) < 10000) {
         if(somecondition) {

I think you have it inverted. You want to wait for the promise to resolve, then loop through your condition checks to make sure user is set or the time has elapsed.

Browse More Popular Posts

Leave a Comment