Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel any outstanding complete timeout before creating a new one #79

Merged
merged 1 commit into from
Jul 21, 2014

Conversation

chrisg2
Copy link
Contributor

@chrisg2 chrisg2 commented Jul 11, 2014

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:

  1. First HTTP request starts and finishes in less than the latencyThreshold, and cfpLoadingBar.complete() is called. cfpLoadingBar.complete() sets up the completeTimeout to clear the loading bar after 500ms.
  2. Before the completeTimeout has occurred, a second HTTP request starts and finishes quicker than latencyThreshold. cfpLoadingBar.complete() is called again, and sets up a 2nd completeTimeout to clear the loading bar after 500ms.
  3. Before either completeTimeout has occurred, a third HTTP request (this one running for longer) starts. cfpLoadingBar.start() is called after latencyThreshold and starts the loading bar. This cancels the 2nd completeTimeout, but not the first completeTimeout.
  4. While the 3rd HTTP request is still running, the first completeTimeout fires and removes the loading bar.

This pull request addresses this by adding the following line to the _complete() function to ensure any existing completeTimeout gets cancelled before setting up another timeout:

$timeout.cancel(completeTimeout);

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!

@chieffancypants
Copy link
Owner

Great catch, and for the unit tests as well!

Unfortunately, it looks like some of my tests are failing (not related to you). Did you have this same issue and you just ignored them?

chieffancypants added a commit that referenced this pull request Jul 21, 2014
Cancel any outstanding complete timeout before creating a new one
@chieffancypants chieffancypants merged commit 7a62d02 into chieffancypants:master Jul 21, 2014
@chieffancypants chieffancypants added this to the next version milestone Jul 21, 2014
@chrisg2
Copy link
Contributor Author

chrisg2 commented Jul 21, 2014

Yes, I did notice a number of tests (from memory, I think it was around 5 tests) failing when I checked out the latest master. I just ignored those failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants