Ratelimit progressbar update to save some cpu time

This commit is contained in:
shortcutme 2017-03-02 23:39:31 +01:00
parent 52ed170292
commit 36db8a4dc9
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE
3 changed files with 50 additions and 3 deletions

View file

@ -0,0 +1,14 @@
limits = {}
call_after_interval = {}
window.RateLimit = (interval, fn) ->
if not limits[fn]
call_after_interval[fn] = false
fn() # First call is not delayed
limits[fn] = setTimeout (->
if call_after_interval[fn]
fn()
delete limits[fn]
delete call_after_interval[fn]
), interval
else # Called within iterval, delay the call
call_after_interval[fn] = true