title: How to call function at fixed interval with ensuring previous function is completed
body: <p>I have a Promise based function which i want to call at fixed interval, Lets say at every 60 seconds. But i also want to make sure that function is called only if the previously called function is executed completely and i want to continue this for infinite time</p>
  
  <pre><code>function fun(){
      return new Promise((resolve,reject)=&gt;{
          //Some database queries which may or may not complete in 60 seconds
          resolve("done")
      })
  }
  
  setInterval(()=&gt;{
      fun().then(d=&gt;{
          console.log(d)
      })
  },60000)
  </code></pre>
  
  <p>Above code will not check for previously called function is completed or not. but i want to make sure that</p>