Improved handling of timing functions for fetching train data #15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've been having problems where this module becomes stuck at a particular time and no longer tries to fetch any updates. I narrowed this down to the case where a request for
GET_TRAININFO
was sent, but due to my internet connectivity being down at the time, this request would never get handled and answered with aTRAIN_DATA
reply. Because the next call toscheduleUpdate()
only occurred after the reply is handled, this would cause the module to get stuck and never update.This PR replaces the
scheduleUpdate()
functionality with an initialsetTimeout()
call instart()
(delaying the first request according to thethis.config.initialLoadDelay
parameter), and then fetching data withsetInterval()
at the appropriate timing fromthis.config.updateInterval
.As this loop doesn't rely on the data actually being received and processed, it will mean any dropped requests do not result in the module becoming frozen.