From d57c54c34fd85fedcc09866716572c926021d13d Mon Sep 17 00:00:00 2001 From: 73cirdan <73cirdan@gmail.com> Date: Wed, 25 May 2022 14:54:40 +0200 Subject: [PATCH] issue #33 - rewrote setTimeout call Signed-off-by: 73cirdan <73cirdan@gmail.com> --- node_helper.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/node_helper.js b/node_helper.js index dba6884..242ff90 100644 --- a/node_helper.js +++ b/node_helper.js @@ -48,10 +48,11 @@ module.exports = NodeHelper.create({ console.log(this.name + " is fetching " + this.config.type + " standings for the " + this.config.season + " season"); const endpoint = this.config.type === "DRIVER" ? "getDriverStandings" : "getConstructorStandings"; const season = (this.config.season === "current", new Date().getFullYear(), this.config.season); + const self=this; f1Api[endpoint](season).then((standings) => { console.log(this.name + " is returning " + this.config.type + " standings for the " + season + " season"); this.sendSocketNotification(this.config.type + "_STANDINGS", standings); - this.standingsTimerId = setTimeout(this.fetchStandings, this.config.reloadInterval); + this.standingsTimerId = setTimeout(function() {self.fetchStandings();}, this.config.reloadInterval); }); }, @@ -62,12 +63,13 @@ module.exports = NodeHelper.create({ fetchSchedule: function () { console.log(this.name + " is fetching the race schedule for the " + this.config.season + " season"); const season = (this.config.season === "current", new Date().getFullYear(), this.config.season); + const self=this; f1Api.getSeasonRacesSchedule(season).then((raceSchedule) => { if (raceSchedule) { raceScheduleDB = raceSchedule; this.sendSocketNotification("RACE_SCHEDULE", raceSchedule); } - this.scheduleTimerId = setTimeout(this.fetchSchedule, this.config.reloadInterval); + this.scheduleTimerId = setTimeout(function() {self.fetchSchedule();}, this.config.reloadInterval); }); },