function count(start, end) { console.log(start) let timer = setInterval(()=>{ console.log(++start) if (start >= end) { clearInterval(timer) } }, 100) return { cancel: () => { clearInterval(timer) }, } }