📜  promise recursive settimeout - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:16.928000             🧑  作者: Mango

代码示例1
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)})