I am creating a simple function to wait until a flag is updated. But when I call await until()
it only gets called once and the timeout never calls the function again. What am I doing wrong?
let flag = true;
const until = async () => new Promise((resolve) => {
if (flag === false) {
resolve("")
} else {
console.log("waiting for flag to be false");
setTimeout(until, 500);
}
});
(async () => await until())();
1