Execute a function on an interval