Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: simple function throttling ( time gate, time limiter, whatever you want to call it )
name
code content
( ~needed_interval = 20; ~funk = { // if last time isn't defined, create it with 1000 seconds ago time if( ~last_time.isNil ) { ~last_time = Date.getDate.bootSeconds; ~last_time = ~last_time - 1000; }; // if needed interval has passed, execute the funkie if( ( Date.getDate.bootSeconds - ~last_time ) > ~needed_interval ) { // safe last execution time, so next calls will have to wait the needed interval ~last_time = Date.getDate.bootSeconds; ( "SOMETHING HAPPENS HERE AT MAXIMUN RATE OF 1 TIME EACH" + ~needed_interval + " SECONDS " ); } { ( "YOU STILL HAVE TO WAIT" ); } }; ) ~funk.value()
code description
A friend of mine asked me how to limit a function to happen at maximun rate of 1 time every N seconds..
use markdown for formating
category tags
comma separated, i.g. "wild, siren" (do not enter default SC class names, please)
ancestor(s)
comma separated identificators, i.g. "1-C,1-1,1-4M,1-x"
Private?
the code will be accessible by direct url and not visible in public activity
signup to submit public code without captcha
comment of change