From 0160a63ad0181819c6c4b009d39351ba609093f2 Mon Sep 17 00:00:00 2001 From: Jens Lody Date: Sun, 13 Sep 2015 10:07:25 +0200 Subject: [PATCH] Better reentrancy guards for forecast.io. The problem here is, that it fetches current and forecast data with one call. --- src/forecast_io.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/forecast_io.js b/src/forecast_io.js index 6dbba88..27e092e 100644 --- a/src/forecast_io.js +++ b/src/forecast_io.js @@ -105,7 +105,8 @@ function parseWeatherCurrent() { return; } - if (this.currentWeatherCache == "in refresh") + if ((this.forecastWeatherCache == "in refresh") || + (this.currentWeatherCache == "in refresh")) return; this.checkPositionInPanel(); @@ -209,6 +210,10 @@ function refreshWeatherCurrent() { } function parseWeatherForecast() { + if ((this.forecastWeatherCache == "in refresh") || + (this.currentWeatherCache == "in refresh")) + return; + 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 @@ -222,9 +227,6 @@ function parseWeatherForecast() { 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);