Skip to content


Subversion checkout URL

You can clone with
Download ZIP


throttle function has bigger delays than it should #820

dcorb opened this Issue · 4 comments

3 participants


I found this minor bug when trying to make a demo to visualize throttle and debounce:

In certain cases, it will skip a execution and waits more (double wait time) than necessary.

I tracked it down to this scenario:

When executing a throttle'd function, there are 2 setTimeouts executed almost simultaneously
with exactly the same delay, AND in this execution order:

  • One for later()
  • One for whenDone() (internally in the _.debounce )

The problem is that later() will trigger a whenDone() also (aka, that same _.debounce)

Then, it can happen two things with that second _.debounce:

  • The first _debounce has finished. [Idealistic]
  • The first _debounce hasn't finished [Problematic], so the second _debounce will clearTimeout the first one.

I continue the bug report with an example in this text file that doesn't break the format:

@jashkenas jashkenas closed this in bb97a4d

Thanks for the report. I've updated the function to use effectively the same implementation as Lodash, removing the two potential timeouts.


Cool !. I updated the blog post to clarify that has been fixed in the master branch.


The updated throttle implementation also resolves issue #502 and helps stabilize existing throttle unit tests (the remaining calculation helps with timeout drift causing false test failings).

Don't forget unit tests (here and here).


Don't forget unit tests (here and here)

Hey, go for it. I've given you push access to the repo.

@cwarden cwarden referenced this issue in jasmine/jasmine

jasmine.Clock.useMock doesn't mock Date #361

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.