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

throttle behavior different from lodash: no trailing edge call #115

Open
jd20 opened this issue Feb 27, 2018 · 2 comments
Open

throttle behavior different from lodash: no trailing edge call #115

jd20 opened this issue Feb 27, 2018 · 2 comments

Comments

@jd20
Copy link

jd20 commented Feb 27, 2018

When using throttle from lodash, if one or more calls are made during the wait period, a single call will be scheduled at the end of the wait period (i.e. the trailing edge). For example:

const throttled = throttle(() => console.log("called"), 5000)
for (var i=0; i < 3; i++) throttled()

You should see the throttled function called twice. However, with pydash, I'm only seeing a single call. If using to check for updates to a resource, you might miss the last update as a result. Here's the equivalent pydash example that I tried:

throttled = throttle(lambda: print("called"), 5000)
[throttled() for _ in range(3)]

Just taking a quick look at the source, pydash's debounce is lacking lodash's leading / trailing options. If those were present and implemented, throttle could just be rewritten as a call to debounce (which is how lodash's throttle is done).

@dgilland
Copy link
Owner

dgilland commented Apr 9, 2018

Care to submit a PR?

@jd20
Copy link
Author

jd20 commented Apr 9, 2018

Sure, I'm backed up with other stuff right now, but I'll try to revisit this later when I get a chance.

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

No branches or pull requests

2 participants