From 24ea75f6c1d81a24393cff27b31b5695d939012e Mon Sep 17 00:00:00 2001 From: baerengraben Date: Tue, 8 Jun 2021 23:34:47 +0200 Subject: [PATCH] https://github.com/baerengraben/ioBroker.swiss-weather-api/issues/42 --- main.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index 5bfc82a..24b15ad 100644 --- a/main.js +++ b/main.js @@ -1027,7 +1027,7 @@ function setCurrentHour(self){ }); } -async function getForecast(self){ +function getForecast(self){ self.log.debug("Getting Forecast for geolocation id: " + geolocationId); today = new Date(); @@ -1063,8 +1063,7 @@ async function getForecast(self){ self.log.info("Getting forecast for GeolocationId: " + geolocationId); //set request - //we have to wait before updating currenthour Objects. - var req = await https.request(options_forecast, function (res) { + var req = https.request(options_forecast, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); @@ -2633,7 +2632,10 @@ async function getForecast(self){ }); }); req.end(); - setCurrentHour(self); + //we have to wait before updating currenthour Objects. + //Instead of going to callback hell, just wait 20s. + // => not a problem if https.request is not finished. In this case, currentHour will be set on every hour (cron) + setTimeout(setCurrentHour, 20000, self); } function getGeolocationId(self,myCallback) {