Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

promise recursive settimeout

function recursiveSetTimeout(iterations) {
  return new Promise((resolve, reject) => {
    function repeat(count) {
     if (!count) return resolve("finished")
      console.log(count)
      setTimeout(repeat.bind(null, count-1), 300)
    }
    repeat(iterations)
  })
}
recursiveSetTimeout(3).then((result)=>{console.log(result)})
 
PREVIOUS NEXT
Tagged: #promise #recursive #settimeout
ADD COMMENT
Topic
Name
6+4 =