Skip to content

Instantly share code, notes, and snippets.

@sansarun
Created June 14, 2016 15:46
Show Gist options
  • Save sansarun/d3d40f529a7aa33f2c288050d1470a2c to your computer and use it in GitHub Desktop.
Save sansarun/d3d40f529a7aa33f2c288050d1470a2c to your computer and use it in GitHub Desktop.
function getSensors(callback) {
var sensorList = [1, 2, 3];
setTimeout(function(){
callback(sensorList);
}, 3000);
}
function getSensorData(id, callback) {
setTimeout(function(){
callback("Sensor data for id:" + id);
}, 3000);
}
getSensors(function(sensorList) {
console.log("sensor list = ", sensorList);
sensorList.forEach(function(sensor, index) {
getSensorData(sensor, function(data) {
console.log(data);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment