It calls
func
up to three times: once when you call it directly:
let delay = func()
and twice more when the timeouts expire:
setTimeout(func, num);
setTimeout(func, delay)
Depending on what
func
returns the first time, the second timeout may expire immediately (if it returns zero), or it may be some considerable time if a large value is returned.
So I'd start by checking what
func
actually does in your code ...