Cancel any outstanding complete timeout before creating a new one #79
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.
angular-loading-bar is a great simple tool to use! Thanks for your work.
I noticed that the bar often doesn't display when making a number of HTTP requests in quick succession where some requests are finishing in less than the latency threshold. The sequence of events is:
latencyThreshold
, andcfpLoadingBar.complete()
is called.cfpLoadingBar.complete()
sets up thecompleteTimeout
to clear the loading bar after 500ms.completeTimeout
has occurred, a second HTTP request starts and finishes quicker thanlatencyThreshold
.cfpLoadingBar.complete()
is called again, and sets up a 2ndcompleteTimeout
to clear the loading bar after 500ms.completeTimeout
has occurred, a third HTTP request (this one running for longer) starts.cfpLoadingBar.start()
is called afterlatencyThreshold
and starts the loading bar. This cancels the 2ndcompleteTimeout
, but not the firstcompleteTimeout
.completeTimeout
fires and removes the loading bar.This pull request addresses this by adding the following line to the
_complete()
function to ensure any existingcompleteTimeout
gets cancelled before setting up another timeout:I have also added a unit test to verify the behavior; the test fails with this change and passes with the change.
I hope this is useful!