Ratelimit progressbar update to save some cpu time
This commit is contained in:
parent
52ed170292
commit
36db8a4dc9
3 changed files with 50 additions and 3 deletions
14
src/Ui/media/lib/RateLimit.coffee
Normal file
14
src/Ui/media/lib/RateLimit.coffee
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue