A safe setInterval function