fix data sharing race condition

This commit is contained in:
Matt Walsh
2020-10-20 20:04:51 -05:00
parent c4e8ef6a14
commit 98e01688ae
8 changed files with 285 additions and 8 deletions

View File

@@ -50,6 +50,9 @@ class Almanac extends WeatherDisplay {
// update status
this.setStatus(STATUS.loaded);
// share data
this.getDataCallback();
}
calcSunMoonData(weatherParameters) {
@@ -320,7 +323,12 @@ class Almanac extends WeatherDisplay {
}
// make sun and moon data available outside this class
getSun() {
return this.data;
// promise allows for data to be requested before it is available
async getSun() {
return new Promise((resolve) => {
if (this.data) resolve(this.data);
// data not available, put it into the data callback queue
this.getDataCallbacks.push(resolve);
});
}
}