To write loops for promise with JavaScript, we use async and await.
For instance, we write
const myFunction = async () => {
//...
while (condition) {
const res = await db.getUser(email);
logger.log(res);
}
};
to use a while loop in the myFunction
function.
In it, we use await
to wait for the promise to resolve and return the value before we move to the next iteration.