pyscript
pyscript copied to clipboard
[Feature Request] Throttle Decorator
I've found ways to implement throttle myself in a few ways but I think it'd be nice if the framework supplied its own.
I could also see it taking in a string for uniqueness like task.unique
.
Thanks!
Perhaps you can share your throttle code as an example of how you'd use this functionality?
throttle_last_run_at = {}
def should_throttle(key, interval):
now = time.time()
last_run = throttle_last_run_at.get(key, 0)
if now - last_run < interval:
return True
else:
throttle_last_run_at[key] = now
return False
@event_trigger("deconz_event", "unique_id == '00:15:8d:00:05:89:13:89'")
def kids_round_switch_pressed(event=None, **kwargs):
if should_throttle('fuss_go', 1):
return