ES6 how to avoid nested functions
I'm not sure I understand what you're asking, but what if you just use setInterval() instead of setTimeout()?



function startWorker(obj) {
  if (!code) {
    setInterval( () =&gt; {
      console.log(obj.action);
    }, 2000);
  }
}

const code = false;
const someObj = {
  action: "tick"
};

startWorker(someObj);