You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • As you say, your problem is that takeReading returns immediately - even though it sets a timeout using setTimeout.

    This is classic JS though. You need to use a callback function:

    Sensor.prototype.takeReading = function(callback) {
      // ...
      setTimeout(function () {
        // ...
        callback(sensorValue);
      }, w);
    };
    
    
    function getAllSensorData() {
      restemp.takeReading(function(resTempVal)­ {
        console.log(resTempVal);
      });
    }
    
About

Avatar for Gordon @Gordon started