title: Schedule an async function in NodeJS
body: <p>I want to schedule a function which is asynchronous (async/await ruturn type) to run for every two minutes.</p>
  <p>I tried with generic <code>setInterval</code>, node modules like <strong>node-schedule , cron, node-cron, async-poll</strong> but unable to achieve polling for a async function call.</p>
  <p>This is what I tried in code:</p>
  <pre><code>cron.schedule(&quot;*/2 * * * *&quot;, await this.servicesManager.startPoll() =&gt; {
                 console.log('running on every two minutes');
  }); // this is not working breaks after first run
              
  const job = schedule.scheduleJob(&quot; */1 * * * *&quot;, async function() {
     try {
           return await this.ServicesManager.startPoll(); // this function startPoll is undefined when using this 
         } catch (e) {
           console.log(e);
     }
     console.log('Run on every minute');
  });
                      
  const event = schedule.scheduleJob(&quot;*/2 * * * *&quot;, this.ServicesManager.startPoll()); //using node-schedule , breaks after first time
  cron.schedule(&quot;*/2 * * * *&quot;, await this.ServicesManager.startPoll()); // using cron same result as using node-schedule
  return await this.ServicesManager.startPoll(); // without polling works
  </code></pre>