Skip to content

throttle function has bigger delays than it should #820

Description

@dcorb

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

http://drupalmotion.com/article/debounce-and-throttle-visual-explanation

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:

http://drupalmotion.com/sites/default/files/demos/throttle.txt

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions