Skip to content

Instantly share code, notes, and snippets.

@Ke-
Last active December 25, 2015 20:19
Show Gist options
  • Select an option

  • Save Ke-/7033558 to your computer and use it in GitHub Desktop.

Select an option

Save Ke-/7033558 to your computer and use it in GitHub Desktop.
Useful for gaining control of active_tick within threads.
<?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