For example in JavaScript, I want to watch a variable and block the control until the variable is changed. I could do something like this:
var foo = 1;
// Some async function that will modify `foo`
while (foo === 1){}
//This code will run after `foo` changes
console.log("New value of foo is", foo);
But is this the right way to achieve that? Is it too hard on CPU?
EDIT: Basically what I want to achieve is, make the code look like it's sync even though there is an async function.
EDIT2: My question isn't duplicate because of the reason mentioned in the edit above.