{
   "ancestor_list" : [],
   "description" : "A friend of mine asked me how to limit a function to happen at maximun rate of 1 time every N seconds..",
   "name" : "simple function throttling ( time gate, time limiter, whatever you want to call it )",
   "author" : "hems",
   "code" : "(\r\n\r\n  ~needed_interval = 20;\r\n\r\n  ~funk = {\r\n\r\n\t// if last time isn't defined, create it with 1000 seconds ago time\r\n\tif( ~last_time.isNil ) {\r\n\t\t~last_time = Date.getDate.bootSeconds;\r\n\t\t~last_time = ~last_time - 1000;\r\n\t};\r\n\r\n\t// if needed interval has passed, execute the funkie\r\n\tif( ( Date.getDate.bootSeconds - ~last_time ) > ~needed_interval ) {\r\n\r\n\t\t// safe last execution time, so next calls will have to wait the needed interval\r\n\t\t~last_time = Date.getDate.bootSeconds;\r\n\r\n\t\t( \"SOMETHING HAPPENS HERE AT MAXIMUN RATE OF 1 TIME EACH\" + ~needed_interval + \" SECONDS \" );\r\n\r\n\t} {\r\n\t\t( \"YOU STILL HAVE TO WAIT\" );\r\n\t}\r\n  };\r\n)\r\n\r\n~funk.value()",
   "is_private" : null,
   "id" : "1-4Vu",
   "labels" : [
      "simple",
      "function",
      "throttling",
      "time",
      "gate",
      "limiter"
   ]
}
