Last active
December 25, 2015 20:19
-
-
Save Ke-/7033558 to your computer and use it in GitHub Desktop.
Useful for gaining control of active_tick within threads.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?lassoscript | |
| /* | |
| Description: | |
| Restricts code from executing more frequently than the specified number of seconds. | |
| Returns the number of seconds to wait until blocks should be executed. | |
| Example: | |
| define my_thread => thread { | |
| public active_tick => every(60) => { | |
| // do stuff | |
| } | |
| } | |
| */ | |
| define every(seconds::integer) => { | |
| local( | |
| gb = givenblock, | |
| v = '_poll_'+#gb->self->type + #gb->methodname, | |
| last = var(#v), | |
| since = #last ? #last->secondsBetween(date) | #seconds | |
| ) | |
| if(#since >= #seconds) => { | |
| handle => { var(#v) = date } | |
| return #gb() || #seconds | |
| else | |
| return (#seconds - #since) | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment