Add reentrency-guards to parseWeatherxxxx-functions.

merge-requests/218/head
Jens Lody 9 years ago
parent c334a925b8
commit 0903deeaa2
  1. 22
      src/forecast_io.js
  2. 10
      src/openweathermap_org.js

@ -93,10 +93,21 @@ function getWeatherIcon(icon) {
function parseWeatherCurrent() {
if (this.currentWeatherCache === undefined) {
// this is a reentrency guard, in this times set for both caches,
// because they get updated with one call to forecast.io
this.currentWeatherCache = "in refresh";
// but do it only if the cache has been cleared, otherwise we would
// overwrite possibly valid data, that can be kept if the update fails
// for some reason
if (this.forecastWeatherCache === undefined)
this.forecastWeatherCache = "in refresh";
this.refreshWeatherCurrent();
return;
}
if (this.currentWeatherCache == "in refresh")
return;
this.checkPositionInPanel();
let json = this.currentWeatherCache;
@ -199,10 +210,21 @@ function refreshWeatherCurrent() {
function parseWeatherForecast() {
if (this.forecastWeatherCache === undefined) {
// this is a reentrency guard, in this times set for both caches,
// because they get updated with one call to forecast.io
this.forecastWeatherCache = "in refresh";
// but do it only if the cache has been cleared, otherwise we would
// overwrite possibly valid data, that can be kept if the update fails
// for some reason
if (this.currentWeatherCache === undefined)
this.currentWeatherCache = "in refresh";
this.refreshWeatherCurrent();
return;
}
if (this.forecastWeatherCache == "in refresh")
return;
let forecast = this.forecastWeatherCache;
let beginOfDay = new Date(new Date().setHours(0, 0, 0, 0));
let cnt = Math.min(this._days_forecast, forecast.length);

@ -290,10 +290,15 @@ function getWeatherCondition(code) {
function parseWeatherCurrent() {
if (this.currentWeatherCache === undefined) {
// this is a reentrency guard
this.currentWeatherCache = "in refresh";
this.refreshWeatherCurrent();
return;
}
if (this.currentWeatherCache == "in refresh")
return;
this.checkPositionInPanel();
let json = this.currentWeatherCache;
@ -406,10 +411,15 @@ function refreshWeatherCurrent() {
function parseWeatherForecast() {
if (this.forecastWeatherCache === undefined) {
// this is a reentrency guard
this.forecastWeatherCache = "in refresh";
this.refreshWeatherForecast();
return;
}
if (this.forecastWeatherCache == "in refresh")
return;
let forecast = this.forecastWeatherCache;
let beginOfDay = new Date(new Date().setHours(0, 0, 0, 0));

Loading…
Cancel
Save