Is there a more readable way to monitor changes of a class variable from its instance?
Although I can use setInterval()
to achieve this, the code becomes quite difficult to read.
let calibrator = new Calibrator("hardwareName");
calibrator.connect();
let monitoring = setInterval(() => {
if (calibrator.getState()) { // The state will be true when there's response from hardware.
clearInterval(monitoring);
// lots of logic here
} else {
// lots of logic here
}
}, 0);
I want the code to clearly indicate that I'm monitoring a class variable. However, using clearInterval()
doesn't convey this high-level logic effectively.
Therefore, I am seeking a better approach to accomplish this task.