Skip to content

debounce based off of inputs#288

Merged
gatesn merged 12 commits into
developfrom
fo/key-input-debounce
Mar 25, 2018
Merged

debounce based off of inputs#288
gatesn merged 12 commits into
developfrom
fo/key-input-debounce

Conversation

@ferozco

@ferozco ferozco commented Mar 14, 2018

Copy link
Copy Markdown
Contributor

key the debouncing off of the value of the inputs. Closes #285

@ferozco ferozco requested a review from gatesn March 14, 2018 23:01
Comment thread pyls/_utils.py Outdated
lock = threading.Lock()

@functools.wraps(func)
def cleanup(*args, **kwargs):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanup_and_run

Comment thread pyls/_utils.py Outdated
def debounce(interval_s, keys=None):
"""Debounce calls to this function until interval_s seconds have passed."""
def wrapper(func):
arg_cache = {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timers

Comment thread pyls/_utils.py
del arg_cache[input_hash]
return func(*args, **kwargs)

@functools.wraps(func)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the wraps decoration

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is wrong. We should leave it on debounced and remove it from cleanup. The decorator basically copies the docstrings / other properties over. No point having it on cleanup. It's debounced that we return

Comment thread pyls/_utils.py Outdated

@functools.wraps(func)
def cleanup(*args, **kwargs):
input_hash = _hash_input(keys, *args, **kwargs)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hoist computing the input_hash up to where you create the lock

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can't do that! the input_hash depends on the input and has to be recomputed each time the function is called. meanwhile the lock is just a member of the debounce closure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yup, you're right. You could pass the key to cleanup as an argument. But not sure you gain much

Comment thread pyls/_utils.py Outdated
return wrapper


def _hash_input(keys, *args, **kwargs):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of this and just use kwargs[key] - can make it more complicate if/when you need it

@gatesn gatesn merged commit 38b744f into develop Mar 25, 2018
@gatesn gatesn deleted the fo/key-input-debounce branch March 25, 2018 08:37
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