mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-17 17:19:30 -07:00
fix data sharing race condition
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user